2014-11-05 123 views
0

我已經構式WAMP-Server,以便它會與一些地方領域的工作,如下: http://proloma http://sweporrWAMP服務器多個域

它的工作原理很好當地使用,但我有2個不同的.com域名指向我的服務器,我怎麼能做到這一點,使互聯網上的人可以通過訪問不同的域訪問不同的頁面?
我的域名是:
www.proloma.com www.sweporr.com
而且他們目前都指向同一個文件夾(c:/ wamp/www)。
我希望他們指出這樣的:
www.proloma.com -> http://proloma www.sweporr.com -> http://sweporr

這是我的httpd-vhosts.conf:

# Virtual Hosts 
# 
# Required modules: mod_log_config 

# If you want to maintain multiple domains/hostnames on your 
# machine you can setup VirtualHost containers for them. Most configurations 
# use only name-based virtual hosts so the server doesn't need to worry about 
# IP addresses. This is indicated by the asterisks in the directives below. 
# 
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.4/vhosts/> 
# for further details before you try to setup virtual hosts. 
# 
# You may use the command line option '-S' to verify your virtual host 
# configuration. 

# 
# VirtualHost example: 
# Almost any Apache directive may go into a VirtualHost container. 
# The first VirtualHost section is used for all requests that do not 
# match a ServerName or ServerAlias in any <VirtualHost> block. 
# 
<VirtualHost *:80> 
    ServerAdmin [email protected] 
    DocumentRoot "C:/wamp/www" 
    ServerName localhost 
    ServerAlias www.localhost.com 
    ErrorLog "logs/localhost-error.log" 
    CustomLog "logs/localhost-access.log" common 
</VirtualHost> 

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    DocumentRoot "C:/Users/Proloma/Dropbox/ProlomaDotCom/www" 
    ServerName proloma 
    <Directory "C:/Users/Proloma/Dropbox/ProlomaDotCom/www"> 
     Options Indexes FollowSymLinks MultiViews 
     AllowOverride None 
     Order allow,deny 
     Allow from all 
    </Directory> 
    ServerAlias www.proloma.com 
    ErrorLog "logs/proloma-error.log" 
    CustomLog "logs/proloma-access.log" common 
</VirtualHost> 

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    DocumentRoot "C:/Users/Proloma/Dropbox/SwePorrDotCom/www" 
    ServerName sweporr 
    <Directory "C:/Users/Proloma/Dropbox/SwePorrDotCom/www"> 
     Options Indexes FollowSymLinks MultiViews 
     AllowOverride None 
     Order allow,deny 
     Allow from all 
    </Directory> 
    ServerAlias www.sweporr.com 
    ErrorLog "logs/sweporr-error.log" 
    CustomLog "logs/sweporr-access.log" common 
</VirtualHost> 

這是我的主人:

# Copyright (c) 1993-2009 Microsoft Corp. 
# 
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows. 
# 
# This file contains the mappings of IP addresses to host names. Each 
# entry should be kept on an individual line. The IP address should 
# be placed in the first column followed by the corresponding host name. 
# The IP address and the host name should be separated by at least one 
# space. 
# 
# Additionally, comments (such as these) may be inserted on individual 
# lines or following the machine name denoted by a '#' symbol. 
# 
# For example: 
# 
#  102.54.94.97  rhino.acme.com   # source server 
#  38.25.63.10  x.acme.com    # x client host 

# localhost name resolution is handled within DNS itself. 
# 127.0.0.1  localhost 
# ::1    localhost 

127.0.0.1  localhost 
127.0.0.1  localhost 
127.0.0.1  localhost 
127.0.0.1  localhost 
127.0.0.1  localhost 
127.0.0.1  localhost 
127.0.0.1  localhost 
127.0.0.1  localhost 
127.0.0.1  proloma 
127.0.0.1  sweporr 

而且我按照所有這些步驟: https://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp

回答

0

我自己修復了!
我只是錯過了部分放
ServerAlias * .proloma.com proloma.com
ServerAlias * .sweporr.com sweporr.com而不是

只是
ServerAlias www.proloma.com

,因爲如果我輸入www而不是如果我只輸入網址等,唯一的WWW情況將只針對正確的服務器。

0

對於虛擬主機,Apache基本上會查看傳入的URL,以決定從哪個虛擬主機使用服務器頁面。

它檢查ServerNameServerAlias參數以找到正確的虛擬主機。因此,您只需更改ServerName參數即可使用正確的.com tld。

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    DocumentRoot "C:/Users/Proloma/Dropbox/ProlomaDotCom/www" 
    ServerName proloma.com 
    ServerAlias www.proloma.com 
    <Directory "C:/Users/Proloma/Dropbox/ProlomaDotCom/www"> 
     Options Indexes FollowSymLinks MultiViews 
     AllowOverride None 
     Order allow,deny 
     Allow from all 
    </Directory> 

    ErrorLog "logs/proloma-error.log" 
    CustomLog "logs/proloma-access.log" common 
</VirtualHost> 

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    DocumentRoot "C:/Users/Proloma/Dropbox/SwePorrDotCom/www" 
    ServerName sweporr.com 
    ServerAlias www.sweporr.com 
    <Directory "C:/Users/Proloma/Dropbox/SwePorrDotCom/www"> 
     Options Indexes FollowSymLinks MultiViews 
     AllowOverride None 
     Order allow,deny 
     Allow from all 
    </Directory> 

    ErrorLog "logs/sweporr-error.log" 
    CustomLog "logs/sweporr-access.log" common 
</VirtualHost> 

您不需要更改HOSTS文件以使其適用於外部互聯網使用,因爲這僅影響本地訪問。

您當然需要Port Forward您的路由器,以便端口80上的外部連接不被拒絕,並且實際上被轉發到運行Apache的PC的IP地址。 這臺PC當然應該有一個靜態IP地址,否則在重新啓動後,它可能會被路由器DHCP服務器給出一個不同的IP地址。