Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save supermasita/decd55c44719005c5adc7ab27d844884 to your computer and use it in GitHub Desktop.
Save supermasita/decd55c44719005c5adc7ab27d844884 to your computer and use it in GitHub Desktop.
NGINX - Determine if user agent is mobile and add set a different proxy_cache_key
location ~ / {
# 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 $ismobile '1';
}
proxy_cache_key $proxy_host$uri$ismobile;
add_header X-Is-Mobile $ismobile;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment