此文以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
刷新浏览器,得到:
文本被重新修改,配置生效了。以上。