Apache2.4.x與Apache2.2.x的一些區別

改用Apache2.4一段時間了,一直沒發現它和Apache2.2的有什麼區別,一些基本配置都是差不多,直到前幾天配置虛擬主機是才發現了一些小小的不同

一直以來我都是在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></VirtualHost>

但是最近我想在目錄htdocs之外配置虛擬主機,還是按照上面的老套路來配置,結果出現的403錯誤:

ForbiddenYou 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/sphinx/api"  ServerName www.mysphinx.com  <Directory "D:/www/sphinx/api">  DirectoryIndex index.html index.php  Require all granted  </Directory></VirtualHost>

發現還是提示403錯誤,只不過這次的錯誤日誌的錯誤變成:

AH01276: Cannot serve directory D:/www/sphinx/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/sphinx/api"  ServerName www.mysphinx.com  <Directory "D:/www/sphinx/api">  Options FollowSymLinks Indexes  Require all granted  </Directory></VirtualHost>

這樣就算大功告成了,不過我敢肯定Apache2.4與Apache2.2的區別不止於此,只是我還沒有發現而已,期待進一步的發現。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章