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

I have a site, www.whatsthatbug.com, being served via varnish/nginx/php-fpm. I am running wordpress with the wptouch pro plugin. This plugin serves a mobile version of the site to mobile users.

Here is how I doing it in Varnish. It seems to work fine if you go directly to m.whatsthatbug.com from a mobile browser, and if you go to any page other than the front page using the www.whatsthatbug.com domain. But if you go to the front page (just www.whatsthatbug.com) from a mobile browser, you are served the regular version of the site. Am I doing something obviously wrong here? Any suggestions?

sub vcl_recv {
    if (req.http.host ~ "m.whatsthatbug.com") {
      set req.http.user-agent = "iphone";
    }

    if ( req.http.user-agent ~
      "(.*iphone.*|.*ipod.*|.*incognito.*|.*webmate.*|.*android.*|.*dream.*|.*cupcake.*|.*froyo.*|.*blackberry9500.*|.*blackberry9520.*|.*blackberry9530.*|.*blackberry9550.*|.*blackberry 9800.*|.*blackberry 9780.*|.*iemobile/7.0.*|.*webos.*|.*s8000.*|.*bada.*|.*googlebot-mobile.*)" )
    {
      set req.http.host = "m.whatsthatbug.com";
    }

    if (req.request == "PURGE") {
            if (!client.ip ~ purge) {
                    error 405 "Not allowed.";
            }
            return(lookup);
    }
    if (req.url ~ "^/$") {
           unset req.http.cookie;
    }
}
share|improve this question
    
If you run varnishlog -b -o | grep Host While you are hitting the site with the www domain, you will be able to see what the host is being set to. That might shed some light on what's happening. Let me know... –  jdw Sep 30 '11 at 10:20
    
The site gets 20-30 hits per second, so that doesn't seem to work. –  danielj Oct 1 '11 at 4:15
    
What doesn't work? –  jdw Oct 1 '11 at 14:54

1 Answer 1

If you're using Varnish 2.1 or newer (which you should), the problem is probably that the regex in your VCL is case sensitive. A snippet from the Varnish 2.1 FAQ

Are regular expressions case sensitive or not? Can I change it?

In 2.1 and newer, regular expressions are case sensitive by default. In earlier versions, they were case insensitive.

To change this for a single regex in 2.1, use (?i) at the start.

See the PCRE man pages for more information.

I can tell that the VCL you're using does not match for iPhone, for example - which could identify itself like this;

Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.