有没有办法从 Varnish 本身发回自定义响应?
if (req.url ~ "^/hello") {
return "hello world";
}
最佳答案
你可以用 synthetic
来做到这一点。回复。例如:
sub vcl_recv {
if (req.url ~ "^/hello") {
error 700 "OK";
}
}
sub vcl_error {
if (obj.status == 700) {
set obj.http.Content-Type = "text/html; charset=utf-8";
set obj.status = 200;
synthetic {"
<html>
<head>
<title>Hello!</title>
</head>
<body>
<h1>Hello world!</h1>
</body>
</html>
"};
}
}
关于varnish - 通过 VCL 从 Varnish 发送自定义响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24520984/