1

I'm running HTTPD on a CentOs 6 server.

I have 2 servers on the same LAN as eachother. I only have 1 IP address. I have 2 domains pointing at the router and I want example1.com handled by server 1 and example2.com handled by server 2. The router can forwards PORT 80 to server 1. I need server 1 to forward traffic directed at example2.com to server 2.

It needs to not interfere with other virtual host targets that look like this:

<VirtualHost *:80>
    DocumentRoot /var/www/html/example1.com
    ServerName example1.com
</VirtualHost>

I tried it using mod_rewrite like this:

<VirtualHost *:80>
    ServerName example2.com
    RewriteEngine On
    RewriteRule .* http://192.168.1.60$0 [P]
</VirtualHost>

but when I load up example2.com in the browser, it tries to load 192.168.1.60, which I can't see because the browser is not on the same LAN as the 2 servers.

How do I do this?

6
  • is NameVirtualHost *:80 defined somewhere in your config ?
    – krisFR
    Apr 29 '15 at 20:49
  • @krisFR I was missing the NameVirtualHost definition. I added it, but it still doesn't work. I'll edit the question to reflect that.
    – Luke
    Apr 29 '15 at 21:05
  • Great. So now your vHost no more overlap. but when I load up example2.com in the browser, it tries to load 192.168.1.60 Is this not what you want ? This is what you config says. If you have Lan subnet issue we are not able to help with infos you provided...describe your network config, routing...(Also note that you said on same lan in your original question title, but not on the same LAN in the question. Please try to clarify)
    – krisFR
    Apr 29 '15 at 21:18
  • @krisFR thanks for helping make this clear. I have 2 server on the same LAN as eachother and I need to be able to load webpage from each of them from outside of the LAN.
    – Luke
    Apr 29 '15 at 21:26
  • You want ProxyPass and ProxyPassReverse.
    – wurtel
    Apr 30 '15 at 8:02
0

This is what I found that ended up working:

<VirtualHost *:80>
    ServerName example2.com
    ProxyPreserveHost On
    ProxyPass / http://192.168.1.60/
    ProxyPassReverse / http://192.168.1.60/
</VirtualHost>

This uses a httpd module called mod_proxy which was enabled by default on my instillation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.