I have a Varnish cache setup in front of my application. I want some routes to be not cached, but completely passed through to other service. I need to preserve headers like X-Forwarded-For so underlying service won't notice anything.
I've tried "pipe" configuration but it didn't worked as I excepted. I'm looking for complete config section.
Config I've tried looked like:
backend blog {
.host = "127.0.0.1";
.port = "8083";
}
sub vcl_recv {
if (req.url ~ "^/blog/") {
set req.backend_hint = blog;
return (pipe);
} else {
set req.backend_hint = default;
}
}
You're looking for return(pass)
, which will not serve the content from the cache and connect directly to the backend.
The return(pipe)
logic is only useful if you're unsure whether or not the incoming request is actually an HTTP request. By piping a request, you take away all notion of HTTP and reduce the data to plain TCP.
Thanks to return(pass)
all headers are maintained.
Here's an updated version of your code example:
vcl 4.1;
backend blog {
.host = "127.0.0.1";
.port = "8083";
}
sub vcl_recv {
if (req.url ~ "^/blog/") {
set req.backend_hint = blog;
return (pass);
} else {
set req.backend_hint = default;
}
}