Reputation: 1
I'm trying to disable caching in varnish for all subdomains. Our application allows users to create and manage their own website on a subdomain of our url, but varnish keeps caching their page when they're trying to edit it.
I know the basic format:
if (req.url ~ "[code here]") {
# Don't cache, pass to backend
return (pass);
}
but nothing I've tried seems to work for all subdomains.
Maybe it's a simple regex?
Upvotes: 0
Views: 2673
Reputation: 379
I think you would need this for any subdomain (note this may be an issue if you use www as it may be considered a subdomain) and will match anything before the . in example.com
sub vcl_recv {
if(req.http.host ~ ".*\.example.com") {
return( pass );
}
}
Upvotes: 0
Reputation: 1678
You can use req.http.host
for this purpose. And yes, it can be a regex.
sub vcl_recv
{
/* your earlier definitions */
if( req.http.host ~ 'my.subdomain.example.com' )
{
// set the backend first
set req.backend = localhost;
return( pass );
}
/* your definitions */
}
In some cases you may need to return( pipe )
:
https://www.varnish-cache.org/docs/2.1/faq/configuration.html
Upvotes: 2