Web Server学习笔记(一):apache配置document root

本文详细介绍在MacOS系统中启动Apache服务器的过程,包括默认DocumentRoot的定位、配置修改及重启验证,帮助读者掌握本地web服务环境搭建技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

此文以macOS系统为例

1 启动apache

$ sudo apachectl start      

在浏览器内打开http://localhost/,我们看到如下界面:
image

2 Document root

Document root,即docroot,是web server文件系统中的一个特殊文件夹,用来存在web content。
apache web server为例,docroot可以通过httpd.conf配置。(macOS中,此文件路径是/etc/apache2/httpd.conf。)
我们可以看到,默认的document root是/Library/WebServer/Documents

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
...

查看此目录

image

我们可以看到,此目录下有index.html.en这个文件。
image

没错,此文件是浏览器访问http://localhost/时,获取到的html文件。

3 配置document root

修改httpd.conf中的document root,路径最后加上test
现在,document root路径是/Library/WebServer/Documents/test
image
我们将原来的index.html.en拷贝到当前document root目录下,并修改其中的文本。
image
然后重启apache

 $ sudo apachectl restart

刷新浏览器,得到:
image
文本被重新修改,配置生效了。以上。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值