如何在Windows wamp服务器中使用相同的ip指向两个网站

时间:2015-10-08 13:09:33

标签: windows apache wamp virtualhost

我有两个网站www.test2.comwampp server。我在Windows IP中托管了两个网站,其中www.test1.com名为xx.xxx.xx.xx。同时打开了两个网站网站www.test1.com即将投放。这些test1个文件位于“www.test2.com”文件夹中,test2位于“wampp”文件夹中。 我在\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf中尝试了虚拟主机......但它无效...

这是我的<VirtualHost *:80> DocumentRoot "c:/wamp/www/test1" ServerName test1 ServerAlias test1.com </VirtualHost> <VirtualHost *:80> DocumentRoot "c:/wamp/www/test2" ServerName localhost ServerAlias test2.com <Directory "c:/wamp/www/test2"> AllowOverride All Require local Require all granted Allow from all </Directory> </VirtualHost> 文件

C:\Windows\System32\drivers\etc\hosts

这是我的127.0.0.1 localhost 127.0.0.1 test1.com 127.0.0.1 test2.com 文件

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)button.getLayoutParams();
    params.removeRule(RelativeLayout.ALIGN_BOTTOM);

2 个答案:

答案 0 :(得分:3)

您的域名都将转到httpd-vhost.conf文件中首先定义的站点,因为这是Apache无法找到主机定义中请求的站点时的默认行为。这通常意味着你在定义你的VHOSTS时做错了。

您的主机定义有点不对,并且您正在混合Apache 2.2和2.4安全语法,这通常会导致问题,请尝试这些

# Should be the first VHOST definition so that it is the default virtual host
# Also access rights should remain restricted to the local PC and the local network
# So that any random ip address attack will recieve an error code and not gain access
<VirtualHost *:80>
    DocumentRoot "C:/wamp/www"
    ServerName localhost
    <Directory  "C:/wamp/www">
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
     DocumentRoot "c:/wamp/www/test1"
     ServerName test1.com
     ServerAlias www.test1.com
     <Directory  "c:/wamp/www/test1">
        AllowOverride All
        Require local
        Require all granted
     </Directory>
 </VirtualHost>

<VirtualHost *:80>
     DocumentRoot "c:/wamp/www/test2"
     ServerName test2.com
     ServerAlias www.test2.com
     <Directory  "c:/wamp/www/test2">
        AllowOverride All
        Require local
        Require all granted
     </Directory>
 </VirtualHost>

现在,您可以在WAMPServer PC上本地查看这些站点,hosts文件应该如下所示。请记住,这些条目仅影响包含HOSTS文件的PC,对互联网访问或远程用户使用这些域名的能力没有影响。

# IPV4 loopback
127.0.0.1      localhost
127.0.0.1      test1.com
127.0.0.1      test2.com
# IPV6 loopback
::1      localhost
::1      test1.com
::1      test2.com

答案 1 :(得分:-1)

第一行需要

NameVirtualHost *:80