2010-07-29 150 views
6

我不知道這裏發生了什麼,但我在Mac OS X上運行甲基苯丙胺1.9在我的httpd.conf文件,DocumentRoot的設置爲默認的htdocs目錄路徑。在htdocs文件夾中,我創建了一些「子網站」,以便將它們設置爲虛擬主機....我可以訪問指定的路徑,但它們似乎都默認爲我設置的第一個路徑。MAC OS X:MAMP環境與虛擬主機

實質上,我配置的第一個虛擬主機是爲site1.localhost.com。我自從配置了site2.localhost.com和site3.localhost.com。但是,轉到最後兩個地址中的任何一個,總是會將我重定向到site1.localhost.com。此外,去localhost.com:8888也只是拉起site1.localhost.com。我不知道我在哪裏犯了一個錯誤的步驟,但希望這裏的某個人能夠幫助我找出問題......哦,並且在重新啓動apache等之後,對/ etc /主機或httpd.conf文件。

在我的httpd.conf文件(相關部分,反正...):

#                                                                    
# DocumentRoot: The directory out of which you will serve your                                                     
# documents. By default, all requests are taken from this directory, but                                                  
# symbolic links and aliases may be used to point to other locations.                                                   
#                                                                    
# MAMP DOCUMENT_ROOT !! Don't remove this line !!                                                        


DocumentRoot "/Applications/MAMP/htdocs" 

#                                                                    
# Note that from this point forward you must specifically allow                                                    
# particular features to be enabled - so if something's not working as                                                   
# you might expect, make sure that you have specifically enabled it                                                   
# below.                                                                  
#                                                                    

#                                                                    
# This should be changed to whatever you set DocumentRoot to.                                                     
#                                                                    
<Directory "/Applications/MAMP/htdocs"> 

<VirtualHost *> 
DocumentRoot "/Applications/MAMP/htdocs/site1/" 
ServerName site1.localhost.com 
</VirtualHost> 

<VirtualHost *> 
DocumentRoot "/Applications/MAMP/htdocs/sub/site2/" 
ServerName site2.localhost.com 
</VirtualHost> 

<VirtualHost *> 
DocumentRoot "/Applications/MAMP/htdocs/sub/site3/" 
ServerName site3.localhost.com 
</VirtualHost> 

在我的/ etc/hosts文件:

##                                                                    
# Host Database                                                                
#                                                                    
# localhost is used to configure the loopback interface                                                      
# when the system is booting. Do not change this entry.                                                      
##                                                                    
127.0.0.1  localhost 
127.0.0.1  site1.localhost.com 
127.0.0.1  site2.localhost.com 
127.0.0.1  site3.localhost.com 
255.255.255.255 broadcasthost 
::1    localhost 
fe80::1%lo0  localhost 

回答

4

在你的httpd.conf文件中找到以下行,並刪除註釋(#):

# NameVirtualHost * 
+0

啊啊啊謝謝!它讓我瘋狂! – locrizak 2011-06-18 19:56:48

0

除了MattLeff的回答,您還應該添加服務器別名,只要是安全的:

ServerAlias www.website.dev 

如果不這樣做,你的瀏覽器自動地補充說:(!和隱藏它,RAWR)的「http // WWW」,那麼你的環境中會自動默認爲第一個虛擬主機。

0

我可以看到你有你的答案。在我的情況下是不夠的。當我添加Chords的建議時,我能夠獲得localhost +許多其他虛擬主機(demo.client.com)在我的MAMP上工作。它只在將本地主機添加爲列表頂部的虛擬主機時起作用。

NameVirtualHost *:80 
<VirtualHost *:80> 
    DocumentRoot "/Applications/MAMP/htdocs" 
    ServerName localhost 
</VirtualHost> 

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    DocumentRoot "/Applications/MAMP/htdocs/clientA/" 
    ServerName clientA.local 
    ErrorLog "logs/clientA-local-error_log" 
    CustomLog "logs/clientA-local-access_log" common 
</VirtualHost>