Skip to content

Instantly share code, notes, and snippets.

@wagura-maurice
Created October 15, 2019 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wagura-maurice/e985733d5a6829b03b77ea73738707e9 to your computer and use it in GitHub Desktop.
Save wagura-maurice/e985733d5a6829b03b77ea73738707e9 to your computer and use it in GitHub Desktop.
Nginx Redirect Mobile / Smart Phone Traffic To Mobile Version Of the Web Site
server {
server_name server_name example-live.com www.example-live.com;
set $mobile_rewrite do_not_perform;
# this regex string is actually much longer to match more mobile devices
if ($http_user_agent ~* "|android|ip(ad|hone|od)|kindle") {
set $mobile_rewrite perform;
}
if ($mobile_rewrite = do_not_perform) {
rewrite ^ http://m.example-live.com$request_uri? redirect;
break;
}
location / {
proxy_pass https://www.example-cloned.com;
}
}
server {
server_name m.example-live.com;
location / {
proxy_pass https://m.example-cloned.com;
}
}
@wagura-maurice
Copy link
Author

if ($http_user_agent ~* "(android|bb\d+|meego).+mobile|avantgo|bada/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)/|plucker|pocket|psp|series(4|6)0|symbian|treo|up.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino") {
set $mobile_rewrite perform;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment