英文:
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 ?!)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论