则提供优雅的对象

则提供优雅的对象

本文介绍了清漆 4:如果 beresp.status 是一个错误,则提供优雅的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在后端响应和交付之间更改交付给客户端的内容?

如果后端返回 4xx 或 5xx 响应(不会被缓存),我正在尝试找出一种方法来继续提供优雅的对象.后端探针命中一个静态页面,只要其上的网络服务器正在运行,它就会保持后端健康,但如果动态页面遇到问题,则会返回错误.

目前,如果探测失败(例如我在后端完全关闭网络服务器),将继续提供优雅的对象.但是如果我只是破坏站点本身,我会看到第一个请求返回缓存的对象并从后端启动新的获取,然后以下请求通过不可缓存的错误(在这种情况下为 404).

我似乎找不到一种方法让 varnish 尝试从后端获取数据,获得错误响应,并提供优雅的对象而不是错误,除非后端被认为是完全不健康的.我错过了一步吗?

解决方案

您可以在配置中添加一些 VCL.请检查我对类似问题的回答:https://stackoverflow.com/a/32970571/1806102.>

想法是(1)在vcl_backend_response期间放弃请求;(2)在vcl_synth期间重启请求;(3) 在 vcl_recv 期间设置一个总是生病的后端;(4) 如果后端出现问题,则在 vcl_hit 期间提供宽限内容.

is there a way to change what is delivered to the client between the backend response and the delivery?

i'm trying to figure out a way to continue to serve graced objects if the backend returns a 4xx or 5xx response (which don't get cached). the backend probe hits a static page, which will keep the backend healthy as long as the webserver on it is running, but dynamic pages will return errors if they run into problems.

currently, graced objects will continue to be served if the probe fails (e.g. i shut down the webserver completely on the backend). but if i just break the site itself, I see the first request returns the cached object and initiates a new fetch from the backend, and then the following requests pass through the non-cacheable error (404 in this case).

I can't seem to find a way for varnish to try to fetch from the backend, get an error response, and serve the graced object instead of the error, unless the backend is recognized as completely unhealthy.am i missing a step?

解决方案

You can do that adding some VCL to your configuration. Please, check my answer to a similar question: https://stackoverflow.com/a/32970571/1806102.

The idea is (1) abandon the request during vcl_backend_response; (2) restart the request during vcl_synth; (3) set a always-sick backend during vcl_recv; and (4) deliver grace content during vcl_hit if the backend is sick.

这篇关于清漆 4:如果 beresp.status 是一个错误,则提供优雅的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 13:01