Nginx 和 Rails 维护页面,让 Squid 2.7 不缓存它们,或者鱿鱼的替代品

发布于 2024-12-26 22:40:26 字数 943 浏览 1 评论 0原文

我在负载均衡器上运行 Squid 2.7,它似乎想要愉快地缓存所有出现的内容,包括(尤其令人烦恼的)维护页面。

维护页面是通过 nginx 错误页面挂钩提供的,所以我似乎对它们的缓存标头没有太多控制权,我只想告诉鱿鱼不要缓存非 200 个页面。有没有办法在不升级鱿鱼的情况下做到这一点? (我知道较新的鱿鱼有一种方法来匹配acl规则上的http状态)

页面本身已经有没有缓存的元标记,但这似乎对鱿鱼没有帮助。

以下是 nginx 发送错误页面的配置:

location / {
  passenger_enabled on;
  passenger_friendly_error_pages off;

  recursive_error_pages on;

  if (-f $document_root/system/maintenance.html) {
    return 503;
  }

  error_page 503 @503;
}

location @503 {
  if (-f $request_filename) {
    return 200;
    break;
  }
  error_page 405 = /system/maintenance.html;
  rewrite ^(.*)$ /system/maintenance.html break;
}

也许有更好的方法在 nginx 端执行此操作,或者也许有某种方法可以向这些错误页面添加额外的内容,从而使它们在鱿鱼中表现得更好。

一般的想法是,如果 document_root/system/maintenance.html 存在,则系统处于维护模式,并且应该为所有请求呈现该页面(静态文件除外,以便页面可以引用样式表或图像或其他内容)

至于鱿鱼最后,我真的没有任何具体的东西可以展示,它是一个非常千篇一律的缓存反向代理设置。


顺便说一句,也许有比使用鱿鱼更好的替代品,我也愿意接受这个建议。

I'm running Squid 2.7 on a load balancer and it seems to want to happily cache anything that comes its way, including (and especially annoyingly)maintenance pages.

The maintenance pages are served through a nginx error page hook, so I don't seem to have that much control over their cache headers, I'd like to just tell squid not to cache non 200 pages. Is there a way to do that without upgrading squid? (I know newer squid has a way to match the http status on acl rules)

The page itself already has meta tags for no cache, but that doesn't seem to help squid.

Here is the bit of config from nginx that sends the error page:

location / {
  passenger_enabled on;
  passenger_friendly_error_pages off;

  recursive_error_pages on;

  if (-f $document_root/system/maintenance.html) {
    return 503;
  }

  error_page 503 @503;
}

location @503 {
  if (-f $request_filename) {
    return 200;
    break;
  }
  error_page 405 = /system/maintenance.html;
  rewrite ^(.*)$ /system/maintenance.html break;
}

Maybe there is a better way to do this on nginx end, or maybe some way to add extra stuff to these error pages ot make them behave better with squid.

The general idea is that if document_root/system/maintenance.html exists, the system is in maintenance mode and that page should be rendered for all requests (except static files so that the page can reference stylesheets or images or whatnot)

As for the squid end, I don't really have anything specific to show for it, its a pretty cookie cutter setup for a caching reverse proxy.


On a flip note, maybe there is a better alternative to using squid, I'm open to that suggestion too.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

变身佩奇 2025-01-02 22:40:26

我知道这不是你想要的,但是这样的东西在系统上要好得多,它提供文件,然后是维护页面(如果它就位),然后回退到支持的服务器

try_files $uri $uri.html /maintenance.html @unicorn_story;

这对于我们来说通过鱿鱼确实工作得很好但我会测试一下。

您也可以在维护结束后清除鱿鱼。

I know this isn't what you are looking for however something like this is much nicer on the system, this serves files then the maintenance page if it is in place then falls back to the backed server

try_files $uri $uri.html /maintenance.html @unicorn_story;

This does work well enough for us via squid but I would test it.

You could also clear squid after coming out of maintainance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文