简体   繁体   English

如何使用清漆页面缓存在magento上启用geoip

[英]How to Enable geoip on magento with varnish page cache

I currently have 3 stores online with 3 different domains, running magento with Apache and varnish (using Phoenix page cache extension) running on centos 我目前在线拥有3个具有3个不同域的商店,并在centos上运行Apache和varnish(使用Phoenix页面缓存扩展名)的magento

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) 麻烦是(示例)如果某个美国用户访问了uk store,我希望收到通知该用户转到页面上的正确商店,(我不希望他们被自动重定向)

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. 我能够使用maxmind数据库进行php-pecl-geoip使其工作,但是随着我网站上用户的增加,我不得不开始使用清漆。

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? 如何使用清漆实现此功能,以便知道用户来自哪个国家/地区,以便向用户显示消息以查看其相关网站?

you can create your Crontroller with a JSON Action Result in Magento. 您可以在Magento中使用JSON操作结果创建Crontroller。 then you can check these with JavaScript and output the result. 然后您可以使用JavaScript检查这些内容并输出结果。

Do not forget to add your controller to the withlist in Varnish. 不要忘记将您的控制器添加到Varnish的withlist中。

Gunah, I think you missed the point here. 古纳(Gunah),我想您错过了这里的重点。 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). 当将Varnish放在Apache的前面时,PHP将看到的客户端IP将始终是Varnish的IP(如果位于同一服务器中,则为127.0.0.1)。

molleman, In this case you need to look at X-Forwarded-For header set by Varnish to get the real client IP. molleman,在这种情况下,您需要查看Varnish设置的X-Forwarded-For标头,以获得真实的客户端IP。 You can see how Varnish set it in the default.vcl: 您可以在default.vcl中查看Varnish的设置方式:

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. 如果您的Web服务器在负载均衡器后面,那么您需要做更多的工作。 Please refer here for a solution: Varnish removes Public IP from X-Forwarded-for 请参阅此处以获取解决方案: Varnish从X-Forwarded-for中删除了公共IP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM