而實際上,這兩個虛擬主機是不存在的,在沒有配置任何其他虛擬主機時,可能會導致訪問localhost時出現(xiàn)如下提示: Forbidden You don't have permission to access /index.php on this server最簡單的辦法就是在它們每行前面加上#,注釋掉就好了,這樣既能參考又不導致其他問題。 5.增加如下配置
復制代碼
代碼如下:
VirtualHost *:80> DocumentRoot "/Library/WebServer/Documents" ServerName localhost ErrorLog "/private/var/log/apache2/localhost-error_log" CustomLog "/private/var/log/apache2/localhost-access_log" common /VirtualHost> VirtualHost *:80> DocumentRoot "/Users/snandy/work" ServerName mysites ErrorLog "/private/var/log/apache2/sites-error_log" CustomLog "/private/var/log/apache2/sites-access_log" common Directory /> Options Indexes FollowSymLinks MultiViews AllowOverride None Order deny,allow Allow from all /Directory> /VirtualHost>
保存退出,并重啟Apache。 6.運行“sudo vi /etc/hosts”,打開hosts配置文件,加入"127.0.0.1 mysites",這樣就可以配置完成sites虛擬主機了,可以訪問“http://mysites”了,在10.8之前Mac OS X版本其內容和“http://localhost/~[用戶名]”完全一致。 7.注意,記錄log的“ErrorLog "/private/var/log/apache2/sites-error_log"”也可以刪掉,但記錄日志其實是一個好習慣,在出現(xiàn)問題時可以幫助我們判斷。如果保留這些log代碼,一定log文件路徑都是存在的,如果隨便修改一個不存在的,會導致Apache無法服務而沒有錯誤提示,這個比較惡心。