Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a Linux box with 2 NICs. I installed and configured Apache 2 for reverse proxy.

Each NIC has its own IP address and I was wondering if there is any way to redirect the requests via Apache based on the IP address that was used to get to the box.

For example: eth0 has IP 100.100.100.100, eth1 has 200.200.200.200

If I browse to http://100.100.100.100/AppName/App I want it to redirect to 1.1.1.1 and if I browse to http://200.200.200.200/AppName/App I want it to go to 2.2.2.2

Right now the configuration for Apache is set as follow

ProxyPass /AppName/App http://1.1.1.1/AppName/App
ProxyPassReverse /AppName/App http://1.1.1.1/AppName/App

So anything going to /AppName/App will be redirected to 1.1.1.1

I was reading something about ProxyHTMLURLMap but I don't know whether this is something that might help.

Any idea how to do this? Thanks!

share|improve this question

2 Answers 2

up vote 0 down vote accepted

This setup seems a little convoluted, I can't help but think that there's a better way to do what you're trying to do - can you expand on your goal so that we might be able to offer better solutions? But, this should do the trick, provided that your users are hitting the site using the IP address as the host:

RewriteCond %{HTTP_HOST} ^100\.100\.100\.100$
RewriteRule ^/AppName/App(.*)$ http://1.1.1.1/AppName/App$1 [P]

RewriteCond %{HTTP_HOST} ^200\.200\.200\.200$
RewriteRule ^/AppName/App(.*)$ http://2.2.2.2/AppName/App$1 [P]

If they aren't, or if you need the 30x-mangling from the ProxyPassReverse, then you'll need to split your vhosts:

<VirtualHost 100.100.100.100:80>
    ...
    ProxyPass /AppName/App http://1.1.1.1/AppName/App
    ProxyPassReverse /AppName/App http://1.1.1.1/AppName/App
</VirtualHost>
<VirtualHost 200.200.200.200:80>
    ...
    ProxyPass /AppName/App http://2.2.2.2/AppName/App
    ProxyPassReverse /AppName/App http://2.2.2.2/AppName/App
</VirtualHost>
share|improve this answer
    
Thanks for the answer. What I am trying to do is essentially separate the requests going into either IPs. I have two application on an internal network (1.1.1.1 and 2.2.2.2) and I would like to redirect to either based on the IP the user used to reach the server. –  Mr Aleph Nov 29 '11 at 16:41
    
Yes, you already said that. It's time to get your head around the idea of virtual hosting. –  adaptr Nov 29 '11 at 16:45

Just add distinct IP-based vhosts.

<VirtualHost 100.100.100.100:80>
    ProxyPass setup #1
</VirtualHost>

<VirtualHost 200.200.200.200:80>
    ProxyPass setup #2
</VirtualHost>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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