2014-12-02 36 views
0

我的虛擬主機是:如何使用虛擬主機在Apache上運行多個項目?

# for localhost to work properly 
<VirtualHost *:1983> 
    ServerAdmin [email protected] 
    DocumentRoot "d:/wamp/www" 
    ServerName localhost 
</VirtualHost> 
# - See more at: http://yogeshchaugule.com/blog/2014/how-setup-virtual-hosts-wamp#sthash.zVhOHBlJ.dpuf 
# - @: http://www.techrepublic.com/blog/smb-technologist/create-virtual-hosts-in-a-wamp-server/ 
# - @: http://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp (maybe out of usable scope) 

# afm : Agile Farm Manager 
#<VirtualHost *:1983> 
# DocumentRoot "D:/projects/afm/Code" 
# ServerName dafm.dev 
# <Directory "D:/projects/afm/Code"> 
# Order allow,deny 
# Allow from all 
# AllowOverride All 
# </Directory> 
#</VirtualHost> 

# mrs : Meeting Request System 
<VirtualHost mrs.dev:1983> 
    DocumentRoot "D:/wamp/www/mrs_site/mrs" 
    ServerName mrs.dev 
    ServerAlias mrs.dev 
    <Directory "D:/wamp/www/mrs_site/mrs"> 
Order allow,deny 
Allow from all 
AllowOverride All 
    </Directory> 
</VirtualHost> 

# dtk : Kit Designer 
<VirtualHost dtk.dev:1983> 
    DocumentRoot "D:/wamp/www/designertoolkit/" 
    ServerName dtk.dev 
    ServerAlias dtk.dev 
    <Directory "D:/wamp/www/designertoolkit/"> 
Order allow,deny 
Allow from all 
AllowOverride All 
    </Directory> 
</VirtualHost> 

我的Windows的hosts文件中有如下映射

#VIRTUAL DOMAINS 

127.0.0.1 dafm.dev 
127.0.0.1 mrs.dev 
127.0.0.1 dtk.dev 

我配置的端口是:1983年,所以我訪問WAMP,如:http://localhost:1983/

http://mrs.dev:1983/去到我目前的項目。但我的其他項目不再可用。

就像我去的時候dtk.dev:1983/對於每一個有效的請求來打開服務器,都會轉到同一個項目http://mrs.dev:1983/

我需要在WAMP同時運行多個項目。虛擬主機有什麼問題?

請幫忙

+0

我也已經根據這些鏈接爲wamp啓用了'vhost_alias_module': - 查看更多:http://yogeshchaugule.com/blog/2014/how-setup-virtual-hosts-wamp#sthash.zVhOHBlJ。 dpuf # - @:http://www.techrepublic.com/blog/smb-technologist/create-virtual-hosts-in-a-wamp-server/ # - @:http://www.kristengrote.com /博客/文章/如何對建立虛擬的主機 - 使用 - WAMP(可能超出使用範圍的) – 2014-12-02 08:29:24

回答

-3

感謝匿名@ user4311956的答案指出了NameVirtualHost指令是很重要的。

但是我自己的測試中,我發現,如果我每個虛擬主機我創建它的工作原理之前提到NameVirtualHost指令,否則失敗。

這裏httpd-vhosts.conf文件中的代碼工作的法寶:對@ user4311956的回答再次

# 
# Use name-based virtual hosting. 
# 
NameVirtualHost *:1983 

# for localhost to work properly 
<VirtualHost *:1983> 
    ServerAdmin [email protected] 
    DocumentRoot "d:/wamp/www" 
    ServerName localhost 
</VirtualHost> 
# - See more at: http://yogeshchaugule.com/blog/2014/how-setup-virtual-hosts-wamp#sthash.zVhOHBlJ.dpuf 
# - @: http://www.techrepublic.com/blog/smb-technologist/create-virtual-hosts-in-a-wamp-server/ 
# - @: http://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp (maybe out of usable scope) 

# afm : Agile Farm Manager 
#<VirtualHost *:1983> 
# DocumentRoot "D:/projects/afm/Code" 
# ServerName dafm.dev 
# <Directory "D:/projects/afm/Code"> 
# Order allow,deny 
# Allow from all 
# AllowOverride All 
# </Directory> 
#</VirtualHost> 
NameVirtualHost mrs.dev:1983 
# mrs : Meeting Request System 
<VirtualHost *:1983> 
    DocumentRoot "D:/wamp/www/mrs_site/mrs" 
    ServerName mrs.dev 
</VirtualHost> 
NameVirtualHost dtk.dev:1983 
# dtk : Kit Designer 
<VirtualHost *:1983> 
    DocumentRoot "D:/wamp/www/designertoolkit/" 
    ServerName dtk.dev 
</VirtualHost> 

感謝您指出我在正確的方向。

+0

您應該只需要一次''NameVirtualHost *:1983>'參數。事實上,如果您使用的是Apache 2.4.x,它實際上不再是一個有效的參數。 – RiggsFolly 2014-12-02 15:19:32

+0

**煤礦服務器是否正在運行:** Windows 7旗艦版 Apache的版本: 2.2.22 PHP版本:5.4.3 但我需要找出一種方法來配置我的本地服務器運行通過多個項目爲每個項目命名虛擬主機。所以我已經完成了我一直在尋找的東西。因此,建議哪種配置並不重要。在發佈到StackOveflow之前,我測試了很多配置。 – 2014-12-03 08:52:24

+0

- 通過上面發佈的這個'config',我可以通過url http:// localhost:1983/designertoolkit /以及虛擬主機http://dtk.dev訪問項目'dtk': 1983' – 2014-12-03 08:52:59

2

您需要使用NameVirtualHost。見Apache的手冊:http://httpd.apache.org/docs/current/vhosts/name-based.html

像這樣:

NameVirtualHost *:80 

<VirtualHost *:80> 
ServerName www.domain.tld 
ServerAlias domain.tld *.domain.tld 
DocumentRoot /www/domain 
</VirtualHost> 

<VirtualHost *:80> 
ServerName www.otherdomain.tld 
DocumentRoot /www/otherdomain 
</VirtualHost> 

也許這是工作:

NameVirtualHost *:1983 

# for localhost to work properly 
<VirtualHost *:1983> 
    ServerAdmin [email protected] 
    DocumentRoot "d:/wamp/www" 
    ServerName localhost 
</VirtualHost> 

# mrs : Meeting Request System 
<VirtualHost *:1983> 
    DocumentRoot "D:/wamp/www/mrs_site/mrs" 
    ServerName mrs.dev 
    ServerAlias mrs.dev 
</VirtualHost> 

# dtk : Kit Designer 
<VirtualHost *:1983> 
    DocumentRoot "D:/wamp/www/designertoolkit/" 
    ServerName dtk.dev 
    ServerAlias dtk.dev 
</VirtualHost> 

<Directory "D:/wamp/www/designertoolkit/"> 
    Order allow,deny 
    Allow from all 
    AllowOverride All 
</Directory> 

<Directory "D:/wamp/www/mrs_site/mrs"> 
    Order allow,deny 
    Allow from all 
    AllowOverride All 
</Directory> 
+0

你說得對'NameVirtualHost'指令,但它必須在每個''定義之前重複。下面我會發布答案和新工作代碼。 – 2014-12-02 13:23:50

+0

你測試了我發佈的配置嗎?我很確定它會以這種方式工作。 – LucasF 2014-12-02 14:37:38

+0

如果您使用我的配置,則不需要爲每個虛擬主機添加'NameVirtualHost'指令。 'NameVirtualHost'將定義給定的IP地址用於命名虛擬主機。在這裏看到:http://httpd.apache.org/docs/current/mod/core.html#namevirtualhost 使用'不推薦NameVirtualHost' DNS名稱。 – LucasF 2014-12-02 14:52:08