Skip to content

Instantly share code, notes, and snippets.

@wokamoto
Last active April 29, 2021 20:08
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wokamoto/9340462 to your computer and use it in GitHub Desktop.
Save wokamoto/9340462 to your computer and use it in GitHub Desktop.
[Nginx] mobile-detect
set $mobile '';
set $mobile_off '';
if ($http_user_agent ~* '(DoCoMo|J-PHONE|Vodafone|MOT-|UP\.Browser|DDIPOCKET|ASTEL|PDXGW|Palmscape|Xiino|sharp pda browser|Windows CE|L-mode|WILLCOM|SoftBank|Semulator|Vemulator|J-EMULATOR|emobile|mixi-mobile-converter|PSP)') {
set $mobile "@ktai";
}
if ($http_user_agent ~* '(iPhone|iPod|incognito|webmate|Android|dream|CUPCAKE|froyo|BlackBerry|webOS|s8000|bada|IEMobile|Googlebot\-Mobile|AdsBot\-Google)') {
set $mobile "@smartphone";
}
if ($http_cookie ~* "wptouch[^\=]+\=(normal|desktop)") {
set $mobile_off "${mobile}.off";
}
if ($mobile_off = "@smartphone.off") {
set $mobile "@smartphone.off";
}
location ~* @(ktai|smartphone|smartphone\.off)$ {
access_log /dev/null;
log_not_found off;
return 404;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment