Created
October 15, 2019 13:17
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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;
}