Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the req.url in vcl_backend_response?

Tags:

My configs are based on Varnish 3.0 and I have been updating them. But I ran into a snag.

vcl_fetch was replace to vcl_backend_response. Inside of vcl_fetch you used to be able to use req.url but not anymore inside of vcl_backend_response.

So I am left with three if statements that won't work:

sub vcl_backend_response {
     set beresp.do_esi = true;

     if (!(req.url ~ "wp-(login|admin)")) {
           unset beresp.http.set-cookie;
     }

     if ( req.http.host ~ "[0-9]\.example\.com" || req.http.host ~ "[0-9]\.example\.com") {
          set beresp.ttl = 60s;
     }

     if ( req.url ~ "\.(html|htm|css|js|txt|xml|svg)(\?[a-z0-9=]+)?$" ) {
          set beresp.do_gzip = true;
     }
}

How do I convert these configs in Varnish version 4.0?

By the way I am new to Varnish VCL.

like image 593
jnbdz Avatar asked Nov 28 '14 21:11

jnbdz


1 Answers

You have to use bereq.url now in vcl_backend_response.

like image 170
Alex Strate Avatar answered Oct 21 '22 13:10

Alex Strate