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.

I'm currently using nginx as reverse proxy with caching enabled.

However, the main site has two different layouts, depending on the user-agent (mobile or not).

I've tried something similar to this:

    # mobile users
    if ($http_user_agent ~* '(iPhone|iPod|mobile|Android|2.0\ MMP|240x320|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|hiptop|IEMobile)') {
            set $iphone_request '1';
    }
    if ($iphone_request = '1') {
            proxy_cache        mobile;
    }
    if ($iphone_request = '') {
            proxy_cache        site;
    }
    proxy_cache_key    "$scheme://$host$request_uri";
    proxy_pass         http://real-site.tld;

However, nginx gives an error, stating proxy_cache can't be used in an if-structure.

Any other way to serve from a different cache depending on the browser?

Thanks, Tuinslak

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Why using different cache? Probably it would be sufficient to define your cache key based on $iphone_request variable?

proxy_cache_key "$iphone_request$uri";
share|improve this answer
    
Indeed, seems to do the trick. Thanks. –  Tuinslak Jun 10 '10 at 15:10
add comment

Redirect to subdomain for mobile devices (with different caching policy)?

share|improve this answer
    
It's actually a Wordpress blog, running a different theme for mobile users. Enabling the mobile theme results in seeing the mobile device layout in a desktop browser if that page has been seen on a mobile device first (and idem dito the other way around). –  Tuinslak Jun 10 '10 at 14:02
add comment

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.