昨天闲来无事,想摸索一下Apache。通过一下午的研究摸索,发现了httpd.conf文件的一些小奥秘。以下罗列出自己总结的,肯定有理解错误的地方,如果有不足或者阐述错误的地方,还望读到这篇文章的您指点
1:以前我们配置虚拟主机的时候是现在hosts文件中添加自己的域名。然后在Apache的apache\conf\extra\httpd-vhosts.conf 文件中添加自己本地项目的目录,以及hosts文件中配置的域名即可,具体语法如下
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "C:/xampp/htdocs/test"
ServerName test.localhost.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
这个在你安装好Apache环境后,httpd-vhosts.conf中都会有对应的例子,按样子复制一份填写好你的项目目录跟域名即可
除了这里可以配置虚拟主机外,在httpd-vhosts.conf的上级目录下,有一个httpd.conf的目录,发现里面有许多平时认为很神奇的事情在这里都能找到根源。如在这里也可以配置虚拟主机 语法如下
<VirtualHost *:80>
DocumentRoot "C:\www"
ServerName test.localhost.com
<Directory "C:\www">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
也许你会发现 如果两个文件中我都配置了同样域名的虚拟主机,那Apache将会以哪个为准呢?经测试将会以httpd-vhosts.conf中的为准,Apache先去httpd-vhosts.conf中去找,如果没有再去httpd.conf中去找。另外还需要有一点注意的地方,就是上面代码标红的地方,两个文件中的 DocumentRoot的项目路径是不同的。
这就牵扯到第二点了:
2:关于报Apache报
Access forbidden!
You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.
If you think this is a server error, please contactthe webmaster.
Error 403
jinyang.localhost.comApache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.15
这个错是由httpd.conf中看看DocumentRoot 的路径与你在httpd.conf 或者httpd-vhosts.conf中对应的项目目录是否对应,如果不对应那么就会报如上的错误。
上面的两个文件中我配置的虚拟主机,DocumentRoot的路径是不同的,如果我在httpd.conf中设置的DocumentRoot的值为 C:/www
那么访问test.localhost.con时就会报如上错误。
3:httpd.conf中还有很多值得去探索的东东,后续我会继续更新。(注:以上所述都为个人见解,如有误区还望指点)