Question

I currently have 3 stores online with 3 different domains, running magento with Apache and varnish (using Phoenix page cache extension) running on centos

One store is for uk, another for Ireland and another for USA

Trouble is (Example) If an US user hits the uk store , I would like the user to be notified to go to the correct store on the page, (I do not want them automatically redirected)

I was able to php-pecl-geoip with maxmind database to get this to work, but as users on my website have increased I had to begin using varnish.

how could I implement this functionality on with varnish so I know what country the user is from so I can display a message to the user to view their relevant website?

Was it helpful?

Solution

Gunah, I think you missed the point here. When put Varnish in front of Apache, the client IP that PHP would see will always be the IP of Varnish (127.0.0.1 if it stay in the same server).

molleman, In this case you need to look at X-Forwarded-For header set by Varnish to get the real client IP. You can see how Varnish set it in the default.vcl:

if (req.http.x-forwarded-for) {
    set req.http.X-Forwarded-For =
    req.http.X-Forwarded-For + ", " + client.ip;
} else {
    set req.http.X-Forwarded-For = client.ip;
}

If your web server is behind a load balancer, then you need more works. Please refer here for a solution: Varnish removes Public IP from X-Forwarded-for

OTHER TIPS

you can create your Crontroller with a JSON Action Result in Magento. then you can check these with JavaScript and output the result.

Do not forget to add your controller to the withlist in Varnish.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top