2024-09-30 01:22:41 发布
网友
这是我正在使用的模块:http://wiki.nginx.org/HttpGeoipModule
据我所见,由于它是在nginx-config和uwsgi上配置的,所以看起来别无选择,只能在每个页面上运行geoip,然后只在需要时收集和使用变量。在
从性能的角度来看,我更希望它能让我只在需要时请求geoip,将其缓存在cookie或会话中,然后不再请求它来加快站点的速度。在
有人能告诉我这是否可能吗?在
不,不能让nginx只按需执行GeoIP查找。由于您定义了一个geoip_country或geoip_city指令,nginx将从geoip数据库请求数据,无论答案是否在以后使用。但是你可以在没有nginx的情况下获取GeoIP数据,也就是说,直接使用你的应用程序。看看python geoip库:http://dev.maxmind.com/geoip/downloadable#Python-5
From a performance point of view I would rather have it so I request the geoip ONLY when needed, cache it in a cookie or session and then not request it again to speed up the site. Is anyone able to tell me if this is possible?`
是的,有可能。但从性能的角度来看,您不必担心,因为geoip数据库存储在内存中(在读取配置阶段),nginx的查找速度非常快。在
不管怎样,如果你愿意,你可以用类似的方法:
set $country $cookie_country; if ($country == '') { set $country $geoip_country_code; add_header Set-Cookie country=$geoip_country_code; } uwsgi_param GEOIP_COUNTRY $country;
不,不能让nginx只按需执行GeoIP查找。由于您定义了一个geoip_country或geoip_city指令,nginx将从geoip数据库请求数据,无论答案是否在以后使用。但是你可以在没有nginx的情况下获取GeoIP数据,也就是说,直接使用你的应用程序。看看python geoip库:http://dev.maxmind.com/geoip/downloadable#Python-5
是的,有可能。但从性能的角度来看,您不必担心,因为geoip数据库存储在内存中(在读取配置阶段),nginx的查找速度非常快。在
不管怎样,如果你愿意,你可以用类似的方法:
相关问题 更多 >
编程相关推荐