简体   繁体   English

使用Varnish和Variant缓存自定义HTTP标头

[英]Caching with Varnish & Varying over custom-set HTTP headers

I'm developing your standard high traffic ecommerce website and want to setup caching with Varnish. 我正在开发您的标准高流量电子商务网站,并希望使用Varnish设置缓存。 The particular thing on this setup is that the application will return different content depending on the user's particular location. 此设置的特别之处在于,应用程序将根据用户的特定位置返回不同的内容。

So my plans are these: 所以我的计划是:

  • Setup Nginx with GeoIP module, so I can get a X-Country: XX header on all the requests going to the app backends. 使用GeoIP模块设置Nginx,这样我就可以在前往应用后端的所有请求上获得X-Country:XX标头。
  • Configure the Rails application to always return a "Vary: X-Country" response header. 配置Rails应用程序以始终返回“ Vary:X-Country”响应标头。
  • Put the Varnish server behind the Nginx and the app backends, so it can cache multiple versions of the objects served by Rails, and serve them based on the request headers set by Nginx ( not the client browser) 将Varnish服务器放置在Nginx和应用程序后端之后,以便它可以缓存Rails服务的多个版本的对象,并根据Nginx设置的请求标头( 而不是客户端浏览器)为它们提供服务

Does anyone have experience with a setup like this? 有人有这样的设置经验吗? Anything I should be aware of? 我应该注意什么?

If GeoIP lookup is slow, and/or you want to enable people to override the country setting, you could use a country cookie and have the front-end Varnish check for it. 如果GeoIP查找速度很慢,并且/或者您想让人们覆盖国家/地区设置,则可以使用国家/地区 Cookie,并进行前端Varnish检查。

  • If there is no country cookie, forward the request to your nginx back-end for GeoIP lookup. 如果没有国家/地区Cookie,请将请求转发到您的Nginx后端以进行GeoIP查找。 Nginx serves a redirect with a Set-Cookie: country=us header. Nginx使用Set-Cookie: country=us标头提供重定向。 If you want to avoid redirects and support cookie-refusing clients/robots, ngingx can forward it to Rails and still try to set the country cookie in the response. 如果您想避免重定向并支持拒绝cookie的客户端/机器人,ngingx可以将其转发到Rails并仍然尝试在响应中设置国家cookie。 Or Varnish can capture the redirect response and do a "restart" with the newly set cookie and go to the back-end 或者Varnish可以捕获重定向响应,并使用新设置的cookie进行“重新启动”,然后转到后端
  • If you have already have a country cookie, use this in your Varnish hash 如果您已经有一个国家/地区Cookie,请在您的Varnish哈希中使用它

If Rails can do GeoIP resolving, you don't need Ngingx, except when you use it to serve files... 如果Rails可以进行GeoIP解析,则不需要Ngingx,除非您使用它来提供文件...

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

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