問題描述:
為apache配置虛擬主機,在httpd-vhosts.conf文件中進行簡單設置,啟動apache進行訪問,卻出現了You don't have permission to access / on this server的提示,原因是我的虛擬主機目錄為非apache安裝目錄下的 .htaccess,所以違反了apache對默認對網站根訪問權限。如圖所示:
配置方式:
apache的默認虛擬主機根目錄地址為/Library/WebServer/Documents/ , 方法如下:
- 更改 Apache 默認網站根目錄需更改 DocumentRoot、Directory .
- 還要記得改一下權限,將 httpd.conf 中的 AllowOverride none,Require all granted ,全部都改成 AllowOverride All,Require all granted ..
- Options指令可以在Apache服務器核心配置(server config)、虛擬主機配置(virtual host)、特定目錄配置(directory)以及.htaccess文件中使用。Options指令的主要作用是控制特定目錄將啟用哪些服務器特性。
- Options FollowSymLinks為禁止Apache顯示該目錄結構,以上問題可以通過下邊兩種方式來解決:
第一,添加Indexes: Options Indexes FollowSymLinks
第二,將其注釋,改為: Options All
# 注意:在Indexes前,加 + 代表允許目錄瀏覽;加 – 代表禁止目錄瀏覽.
<Directory />
AllowOverride All
Require all granted
</Directory>
DocumentRoot "/Users/UserName/Documents/object"
<Directory "/Users/UserName/Documents/object">
# Options FollowSymLinks Multiviews
# MultiviewsMatch Any
Options All
AllowOverride All
# Controls who can get stuff from this server.
Require all granted
</Directory>
重啟Apache: sudo apachectl restart , 在瀏覽器輸入對應地址即可.