varnish - 通过 VCL 从 Varnish 发送自定义响应

标签 varnish varnish-vcl

有没有办法从 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/

相关文章:

apache - Magento + Varnish/ReverseProxy + Apache + DirectAdmin 导致 NET::ERR_CERT_AUTHORITY_INVALID 或 ERR_TOO_MANY_REDIRECTS

c - Varnish 排序查询字符串参数

wordpress - Varnish 4.0 VCL错误: Running VCC-compiler failed

node.js - 在与主后端端口不同的端口上运行 Varnish 探针

varnish - Varnish 默认缓存 404s 吗?

caching - 如何访问 Varnish 管理区域?

linux - 启动 Varnish 缓存 : [FAILED] . .. 如何调试 Varnish ?

magento - Google Analytics(分析)Magento速度问题

nginx - Magento 2通过负载平衡器在多个magento服务器上共享哪些目录?

php - 错误 503 后端获取失败