该光油常见问题建议使用vcl_error这(和它是如何我已经做到了):
这是错误页面的默认VCL:
sub vcl_error {
set obj.http.Content-Type = "text/html; charset=utf-8";
synthetic {"
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>"} obj.status " " obj.response {"</title>
</head>
<body>
<h1>Error "} obj.status " " obj.response {"</h1>
<p>"} obj.response {"</p>
<h3>Guru Meditation:</h3>
<p>XID: "} req.xid {"</p>
<address><a href="http://www.varnish-cache.org/">Varnish</a></address>
</body>
</html>
"};
return(deliver);
}
如果您想要一个自定义版本,只需在配置中覆盖该函数并替换synthetic
语句中的标记即可。
如果您想为不同的错误代码使用不同的标记,也可以很容易地做到这一点:
sub vcl_error {
set obj.http.Content-Type = "text/html; charset=utf-8";
if (obj.status == 404) {
synthetic {"
<!-- Markup for the 404 page goes here -->
"};
} else if (obj.status == 500) {
synthetic {"
<!-- Markup for the 500 page goes here -->
"};
} else {
synthetic {"
<!-- Markup for a generic error page goes here -->
"};
}
}