Error handling 如何自定义503错误-清漆4

Error handling 如何自定义503错误-清漆4,error-handling,varnish,varnish-vcl,http-status-code-503,Error Handling,Varnish,Varnish Vcl,Http Status Code 503,如何自定义Varnish 4的“503后端提取失败” 我正在自定义其他错误,当它们通过synth阶段时: sub vcl_synth { if (resp.status == 750) { set resp.http.location = "http://mobile.cronica.com.ar/"; set resp.status = 302; set resp.http.Action = "Redirect"; r

如何自定义Varnish 4的“503后端提取失败”

我正在自定义其他错误,当它们通过synth阶段时:

sub vcl_synth {
    if (resp.status == 750) {
        set resp.http.location = "http://mobile.cronica.com.ar/";
        set resp.status = 302;
        set resp.http.Action = "Redirect";  
        return(deliver);
    }
    if (resp.status == 751) {
        set resp.status = 301;
        set resp.http.location = "http://www." + req.http.host + req.url;
        set resp.http.Action = "Redirect";
        return(deliver);
    }
    else {
         synthetic( {"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>"} + resp.status + " " + resp.reason + {"</title>
    <link href='http://fonts.googleapis.com/css?family=Oswald:400,700' rel='stylesheet' type='text/css'>

  </head>
  <body style="background-color:#444; font-family: 'Oswald', sans-serif;">
    <h1 style="color:#DD8363;">Error "} + resp.status + " " + {"</h1>
    <p style="color:#5F88C4; ">"} + resp.reason + {"</p>
    <h3 style="color:white;">CEPI Says</h3>
    <p style="color:#bdb76b;">XID: "} + req.xid + {"</p>
    <p style="color:#bdb76b;">Edge-Server: "} + server.hostname + {"</p>
    <hr>
    <p style="color:#65b042;">2.0</p>
  </body>
</html>
"} ); 
        return(deliver);
    }

}
sub-vcl\u合成器{
如果(各自状态==750){
设置resp.http.location=”http://mobile.cronica.com.ar/";
设置相应的状态=302;
设置resp.http.Action=“重定向”;
归还(交付);
}
如果(各自状态==751){
设置响应状态=301;
设置resp.http.location=”http://www.“+req.http.host+req.url;
设置resp.http.Action=“重定向”;
归还(交付);
}
否则{
合成({”
“}+resp.status+”“+resp.reason+{”
错误“}+resp.status++{”

“}+resp.reason+{”

CEPI说 XID:“}+req.XID+{”

边缘服务器:“}+Server.hostname+{”


2.0

"} ); 归还(交付); } }

但是503错误似乎避免了这一点。

根据控制,在
后端错误()之后,
应该传递给
vcl\u synth()
,但实际上,您看到的错误页面是无条件传递的。您可以在那里自定义您的网页,或者在vcl中添加
sub-vcl\u backend\u error{return(retry);}
,以强制跳转到
vcl\u synth()
,这将是
resp.status=503
,太棒了!这就是解决办法。还有一个问题,是否有任何方法将server.hostname(边缘服务器主机名)放在此子目录(vcl_backend_error)中的错误消息中?我不确定您想要什么主机名,
server.hostname
vcl_synth
beresp.backend.name
中提供,
beresp.backend.ip
vcl\u backend\u error
中可用(生成错误的后端,如果没有可用的后端,则为“(null)”。在我的测试中,使用
new vdir=directors.round_robin()且无活动后端
beresp.backend.name+beresp.backend.ip
→ <代码>vdir(空)