Search code examples
apacheproxyreverse-proxyajp

Is it possible to use ProxyPass with only one ip address


I am looking to achieve this configuration. So I tried this but the server is allways looking for server_test and server_prod in the htdocs under Apache. What I want is to redirect the request to the Tomcat server. If I use different ports without the /server_test and /server_prod, it worked but it's not what I wanted.

<virtualhost mydomaine.com/server_test:80>
    ServerName mydomaine.com    
    ProxyRequests Off  
    ProxyPass / ajp://internalIp:8008/
    ProxyPassReverse / http://mydomaine.com/server_test/
    ProxyPassReverseCookiePath / /
</virtualhost>

<virtualhost mydomaine.com/server_prod:80>
    ServerName mydomaine.com    
    ProxyRequests Off     
    ProxyPass / ajp://internalIp:8009/
    ProxyPassReverse / http://mydomaine.com/server_prod/
    ProxyPassReverseCookiePath / /
</virtualhost>

Any help would be appreciated


Solution

  • Try this:

    <virtualhost mydomaine.com:80>
       ServerName mydomaine.com    
       ProxyRequests Off  
       ProxyPass /server_test ajp://internalIp:8008/
       ProxyPass /server_prod ajp://internalIp:8009/
       ProxyPassReverse /server_test ajp://internalIp:8008/
       ProxyPassReverse /server_prod ajp://internalIp:8009/
    </virtualhost>
    

    However, you would not be able to use ProxyPassReverseCookiePath, because both Tomcat sites would set cookies with / as the path.

    To make it work as I believe you want, you need to have two separate VirtualHosts. If you only have one IP address, you need to use name-based virtual hosts.

    For example, add a subdomain test.mydomaine.com that has the same IP address as mydomaine.com. Then use this configuration:

    NameVirtualHost mydomaine.com:80
    <virtualhost mydomaine.com:80>
      ServerName mydomaine.com    
      ProxyRequests Off
      ProxyPass / ajp://internalIp:8009/
      ProxyPassReverse / ajp://internalIp:8009/
    </virtualhost>
    <virtualhost mydomaine.com:80>
      ServerName test.mydomaine.com    
      ProxyRequests Off  
      ProxyPass / ajp://internalIp:8008/
      ProxyPassReverse / ajp://internalIp:8008/
    </virtualhost>
    

    You can then access your production site at http://mydomaine.com/ and your test site at http://test.mydomaine.com/.