varnish multiple backends question about POST

Karagiannidis Yiannis gkaragiannidis at dolnet.gr
Tue Jul 24 17:26:32 CEST 2012


Hi!

I have setup one varnish server for multiple sites running on multiple
backends. 

For example:

Domains: domainA.com, domainB.com running on backend: backendC
Domains: domain0.com, domain1.com running on backend: backend-10
Everything else goes to default backend DC


I also have the following setup

In sub vcl_recv {

if (req.http.host ~ " domainA.com$") {
        unset req.http.cookie;
        set req.backend = backendC;
        return (lookup);
        }

else if (req.http.host ~ "domainB.com$") {
        set req.backend = backendC;
        if ( req.request == "POST" ) {
                                return(pass);
                       }
        return (lookup);
        }

else if (req.http.host ~ "domain0.com$") {
        set req.backend = backend-10;
        if ( req.request == "POST" ) {
                                return(pass);
                       }
        return (lookup);
        }


else {
# Use the default backend for all other requests
set req.backend = default;
return (lookup);
        }

        return (lookup);
}

My problem is that I have POST requests for both domainB.com and domain0.com
and each time I have to use 
set req.backend =
if ( req.request == "POST" ) {
                                return(pass);
in order to pass the request to the correct backend 
Is there a simpler way of handling post requests to different domains?
----------------------------------------------------------------------------
---------------------------------
And a second question if I use 
if (req.request != "GET" && req.request != "HEAD") {
                // Not cacheable by default if NOT GET,HEAD
                return(pass);
        }
Then POST requests are passed to the default backend which, of course gives
me 
an 404 error!

Thanks in advance
Yiannis




More information about the varnish-misc mailing list