Varnish beresp.url – 如何修改来自后端到Varnish的响应?

huangapple go评论52阅读模式
英文:

Varnish beresp.url - How to alter response coming from backend to varnish?

问题

I'm trying to alter a response that send to varnish ( after the initial request ) from varnish backend .

I have the code below that should clean the url querires that sent by backend , vcl_backend_response is the place that i think the code should be placed in order to clean the url before it hits to cache .

The problem is that the beresp.url doesn't exsit and the varnish doesn't compile , can you advise how this can be done ( alter the backend response ? ) ?

vcl_backend_response{

set beresp.url  = regsuball(beresp.url,"(.*?)\?(.*)","\");

}

Thanks in advance
Drad

英文:

I'm trying to alter a response that send to varnish ( after the initial request ) from varnish backend .

I have the code below that should clean the url querires that sent by backend , vcl_backend_response is the place that i think the code should be placed in order to clean the url before it hits to cache .

The problem is that the beresp.url doesn't exsit and the varnish doesn't compile , can you advise how this can be done ( alter the backend response ? ) ?

vcl_backend_response{

set beresp.url  = regsuball(beresp.url,"(.*?)\?(.*)","");

}

Thanks in advance
Drad

答案1

得分: 1

The text you provided contains technical instructions related to Varnish configuration. Here's the translated content without the code:

"Your question is pretty unclear to me.

The bereq.url refers to the URL requested to the backend by Varnish...
And the backend is not answering a URL, it's answering the related content to the URL.
If you need to clean up the requested URL, you should probably do it in either vcl_recv (to avoid multiple cache-variants, see page 216 of the Varnish 6 by Example book).

  • Strip off trailing question marks
    if (req.url ~ "?$") {
    set req.url = regsub(req.url, "?$", "");
    }

or in vcl_backend_fetch, with something like

  • Strip off trailing question marks
    if (bereq.url ~ "?$") {
    set bereq.url = regsub(bereq.url, "?$", "");
    }

Anyhow, you might be able to alter the bereq.url in the beresp procedure (if it helps?!)"

英文:

Your question is pretty unclear to me.

The bereq.url refers to the url requested to the backend by varnish...
And the backend is not answering an URL.. it's answering the related content to the URL
If you need to clean up the requested URL, you should probably do it in the either in the vcl_recv (to avoid multiple cache-variants see page 216 of the Varnish 6 by Example https://info.varnish-software.com/resources/varnish-6-by-example-book)

  # Strip off trailing question marks
  if (req.url ~ "\?$") {
     set req.url = regsub(req.url, "\?$", "");
  }

or into vcl_backend_fetch, with something like

  # Strip off trailing question marks
  if (bereq.url ~ "\?$") {
      set bereq.url = regsub(bereq.url, "\?$", "");
  }

Anyhow, you might be able to alter the bereq.url in the beresp procedure (if it helps ?!)

huangapple
  • 本文由 发表于 2023年4月10日 21:05:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75977390.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定