我已關注本指南foo.dev
我正在嘗試透過允許定向到 web 資料夾來在 OSX 上建立動態虛擬主機/foo
。我的不同之處在於,我使用的~/Sites
是 Web 資料夾,而不是指南中的 Mac HD。它使用 dnsmasq,我相信它已安裝並正常工作。
所以在我的 ~/Sites 資料夾中我有:
home
sites
|-foo
|-bar
我的 httpd-vhosts.conf 如下所示:
<Virtualhost *:80>
DocumentRoot "/Users/harryg/Sites/home"
ServerName home.dev
UseCanonicalName Off
ErrorLog "logs/home/error.log"
<Directory "/Users/harryg/Sites/home">
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Allow from all
</Directory>
</Virtualhost>
<Virtualhost *:80>
VirtualDocumentRoot "/Users/harryg/Sites/sites/%1"
<Directory "/Users/harryg/Sites/sites/%1">
Options FollowSymLinks
#Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Allow from all
</Directory>
ServerName sites.dev
ServerAlias *.dev
UseCanonicalName Off
</Virtualhost>
第一個虛擬主機運作正常,並會導致我在該虛擬主機的根目錄中的home.dev
範例檔案。index.php
無論 .dev 的子網域是否存在資料夾,第二個虛擬主機都會對任何內容給予 403 Forbidden 錯誤。
有任何想法嗎?
編輯:
最新日誌條目
阿帕契錯誤日誌:
[Wed Dec 18 00:45:37 2013] [error] [client 127.0.0.1] File does not exist: /Users/harryg/Sites/home/favicon.ico
[Wed Dec 18 00:45:45 2013] [error] [client 127.0.0.1] client denied by server configuration: /Users/harryg/Sites/sites/test/, referer: http://home.dev/
[Wed Dec 18 00:45:45 2013] [error] [client 127.0.0.1] client denied by server
伺服器現在可以工作(設定檔中的錯誤日誌目錄有問題)。但仍然無法存取動態虛擬主機。
答案1
您的第二個網站的內容是什麼?
可能的原因有兩個:
如果一個目錄沒有指數不允許列出文件(index.php、index.html、default.html 等)和目錄,Apache 將顯示 403 錯誤頁面。
我注意到您沒有在sites.dev 中啟用ExecCGI。您可以嘗試啟用它嗎?
更新:路徑中的百分號 ( /Users/harryg/Sites/sites/%1
) 適用於 mod_vhost_alias,但不是 Apache 的<Directory>
規則。修改一下:
<Directory "/Users/harryg/Sites/sites/%1">
對此:
<Directory "/Users/harryg/Sites/sites">
有效嗎?
答案2
剛剛遇到了同樣的問題,結果發現這是 apache 中的預設值。在 httpd.conf 中是這樣的
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
刪除“拒絕所有”行並重新啟動 apache。
答案3
403 錯誤表示存取被拒絕。您必須檢查樹目錄到網站目錄的權限。
確保執行 apache 的使用者俱有目錄的讀取和執行權限以及檔案的讀取權限。