Configure varnish to pipe a subdomain

Dag-Erling Smørgrav des at linpro.no
Thu Feb 14 12:18:55 CET 2008


Erik <duja at torlen.net> writes:
> Neither am I a regex expert, but I dont think that the regex is the
> problem. You are using http.url instead of using http.host.  And if
> im not totally wrong, you dont need the ~ to check the host, you can
> use ==.
>
> Change this:
> if (req.http.url ~ "admin.example.com$") {
>     pipe;
> }
> To this:
> if (req.http.host == "admin.example.com") {
>     pipe;
> }
>
> And this:
> if (req.http.Cookie && req.http.url ~ "admin.example.com$") {
>     pipe;
> }
>
> To this:
> if (req.http.Cookie && req.http.host == "admin.example.com") {
>     pipe;
> }

A couple of issues:

 - a regexp is better if you get it right, because a regexp match
   (unlike a string comparison) is case-insensitive by default.

 - pass is better than pipe, unless pipe is required for other
   reasons, in which case "Connection: close" should be added to the
   request headers.

 - the second if will never evalutate to true, since the first one
   trumps it.

The correct code would be:

if (req.http.url ~ "^admin.example.com$") {
        pass;
}

DES
-- 
Dag-Erling Smørgrav
Senior Software Developer
Linpro AS - www.linpro.no



More information about the varnish-misc mailing list