此文以macOS系统为例
1 启动apache
$ sudo apachectl start
在浏览器内打开http://localhost/,我们看到如下界面:

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">
...
查看此目录

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

没错,此文件是浏览器访问http://localhost/时,获取到的html文件。
3 配置document root
修改httpd.conf中的document root,路径最后加上test
现在,document root路径是/Library/WebServer/Documents/test

我们将原来的index.html.en拷贝到当前document root目录下,并修改其中的文本。

然后重启apache
$ sudo apachectl restart
刷新浏览器,得到:

文本被重新修改,配置生效了。以上。
本文详细介绍在MacOS系统中启动Apache服务器的过程,包括默认DocumentRoot的定位、配置修改及重启验证,帮助读者掌握本地web服务环境搭建技巧。
:apache配置document root&spm=1001.2101.3001.5002&articleId=102187592&d=1&t=3&u=b800bbccf98c479b964574e10b5ed07a)
3668

被折叠的 条评论
为什么被折叠?



