Httpd VirtualHosts有两个IP

时间:2014-10-17 06:57:24

标签: amazon-ec2 tomcat7 virtualhost httpd.conf

必须从他们自己的IP访问两个webapp(每个都专用于网络接口):

  1. Webapp A正在httpd服务器上运行php模块,IP 142.xxx.xxx.xxx
  2. Webapp B正在tomcat7服务器上运行,IP 143.xxx.xxx.xxx
  3. 的httpd.conf

    Listen 80
    Listen 443
    
    NameVirtualHost 142.xxx.xxx.xxx:80  
    NameVirtualHost 143.xxx.xxx.xxx:80
    
    # Webapp A
    <VirtualHost 142.xxx.xxx.xxx:80>
        ServerName ASite
        DocumentRoot /mnt/data/www/html
    </VirtualHost>
    
    # Webapp B
    <VirtualHost 143.xxx.xxx.xxx:80>
        ServerName Bsite
        ProxyPreserveHost On
        ProxyRequests On
        ProxyVia On
        ProxyPass / http://www.siteb.com:8081/
        ProxyPassReverse / http://www.siteb.com:8081/
        #<Proxy *>
        #   Order deny,allow
        #   Deny from all
        #   Allow from 54.171.140.42
        #</Proxy>   
    </VirtualHost>
    

    问题:无论输入什么ip / dns来源,端点始终是站点A,除非Webapp B配置了<VirtualHost *:80>,它将所有请求重定向(代理)到tomcat webapp B.如何映射重定向相应的?

1 个答案:

答案 0 :(得分:0)

错误与VirtualHost指令中的IP分配有关(httpd解析为服务器的名称):

NameVirtualHost *:80

# Webapp A
<VirtualHost *:80>
    ServerName ASite
    DocumentRoot /mnt/data/www/html
</VirtualHost>

# Webapp B
<VirtualHost *:80>
    ServerName Bsite
    ProxyPreserveHost On
    ProxyRequests On
    ProxyVia On