nginx caching per user agent
Posted
by Tuinslak
on Server Fault
See other posts from Server Fault
or by Tuinslak
Published on 2010-06-10T13:20:14Z
Indexed on
2010/06/10
13:23 UTC
Read the original article
Hit count: 222
nginx
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
© Server Fault or respective owner