Search code examples
apachehttp-redirectproxyreverse-proxyports

Redirect to a different apache server for a Domain but keep URL the same


Hopefully this is easy to do - I just can't figure it out!

I apologise in advance if I get any of the terminology wrong is the question. My knowledge of web servers is not brilliant!

I have two apache servers within one domain. One is listening on port 80 (we can call it Apache1) and the other on port 10080 (Apache2).

What I want to achieve is that when a user enters a certain domain address in the URL bar in the browser (say www.domain.com) , they get redirected from the default server on port 80 to the server listening on port 10088.

I have achieved this using the Redirect keyword in the Apache httpd.conf file of the Apache 1 server like this:-

<VirtualHost *:80>
ServerName www.domain.com
Redirect / http://www.domain.com:10088/exampleApp
</VirtualHost>

While this works, unfortunately it changes the URL in the browser to www.domain.com:10088/exampleApp where I need it to appear to the user with the same domain they entered - www.domain.com

I have tried messing around with ProxyPass and ReverseProxyPass but I could get this to work. I don't know if a solution can be achieved using URL rewriting or not.

Thanks in advance for any help


Solution

  • You need to use a reverse proxy for this:

    If both of your sites are listening on the same server, you can probably just proxy on localhost (127.0.0.1). If not, make sure the domain name can be resolved from Apache1

    <VirtualHost *:80>
      ServerName www.domain.com
    
      ProxyPreserveHost On
      ProxyPass / http://127.0.0.1:10088/exampleApp/
      ProxyPassReverse / http://127.0.0.1:10088/exampleApp/
    </VirtualHost>