Skip to content

Instantly share code, notes, and snippets.

Forked from perusio/gist:1326701
Last active August 23, 2017 12:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
[Mobile device detection in Nginx] with just 7 lines of configuration #nginx
### Testing if the client is a mobile or a desktop.
### The selection is based on the usual UA strings for desktop browsers.
## Testing a user agent using a method that reverts the logic of the
## UA detection. Inspired by
map $http_user_agent $is_desktop {
default 0;
~*linux.*android|windows\s+(?:ce|phone) 0; # exceptions to the rule
~*spider|crawl|slurp|bot 1; # bots
~*windows|linux|os\s+x\s*[\d\._]+|solaris|bsd 1; # OSes
## Revert the logic.
map $is_desktop $is_mobile {
1 0;
0 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment