Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Having an issue with Varnish returning the wrong backend. I have several backends listening on ports 8080 through 8095 on vhosts in Apache. I configured my Varnish backends like so:

acl purge {
    "localhost";
    "192.168.0.1";
}

backend default {
    .host = "192.168.0.1";
    .port = "8094";
    .connect_timeout =  20s; #600s;
    .first_byte_timeout = 20s; #600s;
    .between_bytes_timeout = 20s; #600s;
}

backend default_mobile {
    .host = "192.168.0.1";
    .port = "8093";
    .connect_timeout =  20s; #600s;
    .first_byte_timeout = 20s; #600s;
    .between_bytes_timeout = 20s; #600s;
}

backend secondary {
    .host = "192.168.0.1";
    .port = "8082";
    .connect_timeout =  20s; #600s;
    .first_byte_timeout = 20s; #600s;
    .between_bytes_timeout = 20s; #600s;
}

backend secondary_mobile {
    .host = "192.168.0.1";
    .port = "8083";
    .connect_timeout =  20s; #600s;
    .first_byte_timeout = 20s; #600s;
    .between_bytes_timeout = 20s; #600s;
}

This works well most of the time but after some time (several hours) we'll get reports of users seeing the wrong site under the wrong URL. For instance they'll go to www.example.com and get a page from the secondary_mobile backend. It's always the same backend that is returned incorrectly and the URL in the browser will show the intended site (www.example.com). We don't have any sort of redirects in Apache so I'm unsure how it's getting confused. Here's an example of how I set the backends:

....
if ( req.http.host ~ "example.com$" ) { 
    set req.backend = default;
    set req.http.host = "www.example.com";
} else if ( req.http.host ~ "^(www.)?example2.com$" ) { 
    set req.backend = secondary;
    set req.http.host = "www.example2.com";
} else if ( req.http.host ~ "^(m.)?example2.com$" ) { 
    set req.backend = secondary_mobile;
    set req.http.host = "m.example2.com";
....

I thought manually specifying the host was enough but apparently not. The Varnish docs don't have a lot on the subject either.

share|improve this question
    
Do you have the logs of one of the requests that went wrong? You can also add some log statements to help identify in the logs what's going on . –  arjarj Apr 26 '12 at 18:24
    
I don't have them anymore but I did notice the requests that didn't serve properly hadn't specified a set backend in the varnishlog output. I think that just meant they were served from cache though. –  Thomas Hibbard Apr 26 '12 at 18:35
    
Actually I cannot see a big problem in the given example configuration. Regarding redirects, keep in mind that you do not need mod_rewrite for that. A common request to the folder "/xyz" will be redirected to "/xyz/" . Additionally I miss something to handle IP based requests (e.g. 1.2.3.4/xyz ) or even complete different host names (e.g. crazybot/xyz ). Without anymore details it's hard to investigate. We are using some comparable set-ups but don't have this problem (it hasn't been reported yet). –  Jens Bradler Apr 27 '12 at 17:10
    
Well, running varnishlog -i Backend_health does return the default backend which is what I want but the response is definitely from another backend. It's also having timeout issues. Which I thought I had handled with a grace setting of 7 minutes. Back to the drawing board is seems. –  Thomas Hibbard May 1 '12 at 4:06
    
Please check if the data from the wrong back-end isn't staled or expired data. Usually you can check the Age header for this. I assume that everything is working fine but you are getting this data in case your back-end doesn't respond fast enough. –  Jens Bradler May 1 '12 at 14:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.