varnish3, mod_geoip with apache2 using mod_rewrite and mod_rpaf

Posted by mursalat on Server Fault See other posts from Server Fault or by mursalat
Published on 2012-06-28T12:33:43Z Indexed on 2012/06/28 15:18 UTC
Read the original article Hit count: 471

Filed under:
|
|
|
|

I am maintaining a website with 3 different versions of the site, with 3 different languages, handles with a single system written in php, which takes in environment variables based on the domain name that is being accessed. These are the three sites:

  • myshop.com : english international version
  • myshop.eu : european version of site
  • myshop.ru : russian version of the site

when myshop.com is accessed from russia it is to be redirected to myshop.ru, and any country from europe accesses myshop.com, is redirected to myshop.eu, and international visitors stay at myshop.com, although they can go to the country specific site. All these redirections for the country is done using GeoIP apache2 mod in order to determine the country code, which is used in a RewriteCondition to state a RewriteRule, there are some exceptions of IPs that do not do the rewrite for, basically the IPs of the developer's PCs. The site has been doing just fine, until we decided to setup varnish to give the site a boost, it really did give it a great boost, but the country specific rewrites has become buggy.

What started to happen is that a russian visitor can go to myshop.com and won't be redirected, until he clicks a random link (perhaps a link not cached by varnish yet) and the user is redirected to their specific country.

For that i setup mod_rpaf, and for exceptions to the rewrite rule (for the developer's ip), i used this RewriteCond %{HTTP:X-FORWARDED-FOR} !^43\.43\.43\.43, and i restarted varnish and apache2, it worked for a while, then it messed up again.

And whole day i have been doing changes however i have little no clue as to what's going on, sometimes it works, and sometimes it doesn't, and sometimes it half works, etc...

As for geoip, i used a php to check the $_SERVER variable, and here is the general idea of the output

[HTTP_X_FORWARDED_FOR] => 43.43.43.44
[HTTP_X_VARNISH] => 1705675599
[SERVER_ADDR] => 127.0.0.1
[SERVER_PORT] => 80
[REMOTE_ADDR] => 43.43.43.44
[GEOIP_ADDR] => 43.43.43.44
[GEOIP_CONTINENT_CODE] => EU
[GEOIP_COUNTRY_CODE] => FR
[GEOIP_COUNTRY_NAME] => France

Now, thanks to the "random" redirects, i hardly have a clue as to what is going on, so can you guys please give me some ideas as to what tools to use to debug this? I have tried to see the redirect logs, but they really dont show much, and varnishlog isn't helping much either - although i must admit i am no professional at varnish.

I believe the problem is with varnish trying to cache the url, and thus apache redirects are not being done properly, however visits the site first has a redirect, and based on that other users are served the content, depending on from where the user was when the cache was last updated, is it correct? if so, how can i solve the problem?

Also, i have the option of using geoip redirects on varnish3 instead of using apache2 to do the redirects, is that what the best practice is? Any suggestion as to debugging this or to fix this would be helpful!

thnx!

© Server Fault or respective owner

Related posts about apache2

Related posts about mod-rewrite