Operating System - HP-UX
1832978 Members
3211 Online
110048 Solutions
New Discussion

URL Redirection based on IP Address

 
Yogeeraj_1
Honored Contributor

URL Redirection based on IP Address

Hi experts,

We need to find a way to REDIRECT http requests to "apps.msvr.mu" to "apps2.msvr.mu" based on the IP address of the client browser.

In our setup, we have two sites (LAN1, LAN2) running over a WAN. We have 2 DNSes - one at each site.

On LAN1 and LAN2, our client browsers currently have default home page set to "apps.msvr.mu". "apps2.msvr.mu" is our new server.

We want our future setup as follows:

LAN1 => "apps.msvr.mu"
LAN2 => "apps2.msvr.mu"

We want to load balance with the least modification on the client side.

FYI: we have been able to "redirect" all the requests from apps.msvr.mu to apps2.msvr.mu but could not do the load sharing based on IP address of client.
[using ProxyPass / http://apps2.msvr.mu/ ]

Any solution at the apache level?
Any solution at the DNS level?


Thank you in advance for your replies!


best regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
5 REPLIES 5
Sritharan
Valued Contributor

Re: URL Redirection based on IP Address

Hi,

Need to clarify your question
<> what you mean by this

By what I understand you can redirect the page by at apache level

There are two techniques to implement canonical hostnames:

Use mod_rewrite as described in the "Canonical Hostnames" section of the URL Rewriting Guide.
Use name-based virtual hosting:
NameVirtualHost *


ServerName www.example.net
ServerAlias example.com
Redirect permanent / http://www.example.com/



ServerName www.example.com
DocumentRoot /usr/local/apache/htdocs



On the DNS side maybe you can set that LAN2 user DNS will be pointing to your new server staight and do a redirect page in the server.

This is what I understand from your question
Please reply to this
Thanks & Regards
Sri
Known is a drop...unknown is an ocean -> quote from a movie
Steven E. Protter
Exalted Contributor

Re: URL Redirection based on IP Address

On the DNS side, you can not only achieve your goal but also provide redundancy and failover in case a DNS or httpd server goes down.

You need to have to master DNS servers, one for each lan, with slightly different records.

I'll try and use your example.

DNS is normally auto-assigned to microsoft clients so you do the following on the client side:

LAN1
DNS Primary is dns.apps.msvr.mu
DNS Secondarry is dns.apps2.msver.mu

LAN2
DNS Primary is dns.apps2.msvr.mu
DNS Secondarry is dns.apps.msver.mu

If one DNS server is down there is failover. You don't need very much bandwidth to handle the DNS requests. The httpd traffic shouldn't be too much of a strain. The Oracle data, thats hard to tell.

LAN1 => "apps.msvr.mu"
LAN2 => "apps2.msvr.mu"

LAN1 's DNS server
has a zone for apps.msvr.mu which resolves locally and a zone for apps2.msvr.mu that resolves to IP addresses on the apps2 side of the house.

LAN2 has the zone records reversed of LAN1

That accomplishes your goal purely with DNS.

You might look into named or IP based virtual hosting directives on the apache side to provide further redundancy or load balancing.

http://httpd.apache.org/docs-2.0/vhosts/name-based.html
http://httpd.apache.org/docs-2.0/vhosts/ip-based.html

With the same general concept, you can probably accomplish the same thing we did above with dns in httpd.conf

Again, based on your example.

A directive in httpd.conf on the LAN1 side.


Lets say apps resolves to 192.168.143.198
Lets say apps resolves to 192.168.144.198


ServerAdmin you@yourdomain.com
DocumentRoot /home/webusers/apps/htdocs
ServerName apps.msvr.mu:80
ScriptAlias /cgi-bin/ "/home/webusers/apps/cgi-bin/"
ErrorLog logs/apps.error_log
CustomLog logs/apps.com.access_log common



ServerAdmin you@yourdomain.com
DocumentRoot /home/webusers/apps2/htdocs
ServerName apps2.msvr.mu:80
ScriptAlias /cgi-bin/ "/home/webusers/apps2/cgi-bin/"
ErrorLog logs/apps2.error_log
CustomLog logs/apps.2com.access_log common


Have the same directives in httpd.conf on the LAN2 side and you can with a little tweaking load balance quite nicely.

It doesn't matter what the client IP address is, it matters what its DNS or httpd server tells the client to do.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Yogeeraj_1
Honored Contributor

Re: URL Redirection based on IP Address

hi,

thank you both for your replies.

I have not yet tested the solutions you have provided.

In the scenario i presented in my question, i mentioned about 2 LANs but in fact i have 4!

I already have the DNS setup as SEP outlined above. The problem is:
-----Primary DNS-----------Secondary DNS
LAN1: dns.apps2.mysvr.mu<->dns.apps1.mysvr.mu
LAN2: dns.apps2.mysvr.mu<->dns.apps1.mysvr.mu
LAN3: dns.apps1.mysvr.mu<->dns.apps2.mysvr.mu
LAN4: dns.apps1.mysvr.mu<->dns.apps2.mysvr.mu

I don't want the DNS changes to affect clients on LAN2... :(

any more ideas?

best regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
oiram
Regular Advisor

Re: URL Redirection based on IP Address

Hi,

You can do what you want in this way. First you must set an evironment variable for each destination server using the value of the client ip(http://httpd.apache.org/docs/mod/mod_setenvif.html, setenvif directive). After that you can use mod_rewrite(http://httpd.apache.org/docs/mod/mod_rewrite.html#RewriteCond). The first part isn??t necessary but I think it would be better to define a range of ip addresses associated to a variable and then use this variable to make the redirection.

Regards.
Ron Kinner
Honored Contributor

Re: URL Redirection based on IP Address

Do you have Cisco routers on your WAN? Policy routing and a bit of creative secondary addressing or NAT could also do what you want.

Ron