以前一直在用Apache2.2,最近升級了apache版本,改用Apache2.4時感覺一些基本配置都是差不多,但是配置虛擬主機時發現有些不同,現在再對比一下整理出來.
一直以來我都是在htdocs目錄下配置虛擬主機的,大體上使用的方法如下:
- <VirtualHost *:80>
- DocumentRoot "D:/www/Apache24/htdocs"
- ServerName localhost
- <Directory D:/www/Apache24/htdocs>
- DirectoryIndex index.html index.php
- Order Deny,Allow
- Allow from all
- </Directory>
但是最近我想在目錄htdocs之外配置虛擬主機,還是按照上面的老套路來配置,結果出現的403錯誤:
<span style="font-size: 16px;"><strong>Forbidden</strong></span>
You don't have permission to access / on this server.
瞬間沒了頭緒,這是在Apache2.2所沒有的出現過的情況啊,然后試著將虛擬主機的根目錄改成htdocs目錄之下,也就是:
DocumentRoot "D:/www/Apache24/htdocs/test"
發現網站又能正常運行了,反復試了多次都是同一的結果,然后我就想到底是哪個地方出現了問題,這個問題困擾了我幾天,百度找了無數答案,大部分都是說目錄的權限有錯誤,需要修改權限,或者是selinux設置的問題,可是我運行的環境是windows,所以這些情況也被排除在外;有些說是需要設置Allow from all,也沒有效果.
通過查看錯誤日志,發現有那么一行:
AH01630: client denied by server configuration: D:/www/
但是我的Order指令設置都是正確的,這樣我郁悶了一段時間,無意中發現了一篇文章描述Apache2.4與Apache2.2之間的一些指令的差異,剛好解決了我的問題,其中的一些指令已經無效,如:
- Order Deny,Allow
- Deny from all
- Allow from al
- //取而代之的是:
- Deny from all
- //變成
- Require all denied
- Allow from all
- //變成
- Require all granted
于是我將虛擬機配置為:
- <VirtualHost *:80>
- DocumentRoot "D:/www/Vevb/api"
- ServerName www.49028c.com
- <Directory "D:/www/Vevb/api">
- DirectoryIndex index.html index.php
- Require all granted
- </Directory>
- </VirtualHost>
發現還是提示403錯誤,只不過這次的錯誤日志的錯誤變成:
AH01276:Cannot serve directory D:/www/Vevb/api/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive
這是因為里面的根目錄里面沒有index.html 或者 index.php,我們可以添加index.html文件或者將設置改成如下:
- <VirtualHost *:80>
- DocumentRoot "D:/www/Vevb/api"
- ServerName www.49028c.com
- <Directory "D:/www/Vevb/api">
- Options FollowSymLinks Indexes
- Require all granted
- </Directory>
- </VirtualHost>
大功告成了,不過我敢肯定Apache2.4與Apache2.2的區別不止于此,只是我還沒有發現而已,期待進一步的發現.
新聞熱點
疑難解答