Nginx 怎么配置根据 User-Agent 跳转到不通地址
比如,跳转到移动端的网站
我怎么配都跳转不过去
|      1willakira      2017-04-05 12:54:36 +08:00 强烈不推荐这么做,如果是用于生产环境的话 Nginx 、 apache 、 tomcat 这些 server 的配置一般不是由开发来管理的,因此 - 每次更新的时候都需要运维参与 - 出现问题的时候回滚非常麻烦 - 性能倒是其次, debug 会非常复杂 一般都会在 container 跑个小程序做这个,好处有 - 自己更新 - 出问题了自己回滚 - 容易 debug 把难以监控,不透明的东西做的简单,复杂的东西做的透明,就是这样 | 
|  |      2sundong      2017-04-05 13:39:08 +08:00 ## rewrite spider if ($http_user_agent ~* (baiduspider|googlebot|Googlebot|soso|bing|sogou|yahoo|sohu-search|yodao|YoudaoBot|robozilla|msnbot)) { rewrite ^/(.*)$ https://www.baidu.com permanent; } | 
|      3luojiyin87      2017-04-05 14:27:05 +08:00  2 | 
|  |      4chuhemiao      2017-04-05 14:32:22 +08:00 直接上代码不好吗,干吗要 nginx 配置, php 扩展有手机类型,直接判断了,然走那就走那 | 
|  |      5SourceMan      2017-04-05 14:33:13 +08:00 前端、后端做,都轮不到运维做。。。 | 
|  |      6prasanta      2017-04-05 14:37:12 +08:00 现在网站直接响应式了 | 
|  |      7Cabana      2017-04-05 18:36:29 +08:00 via Android 咋不做响应式呢 | 
|  |      8Showfom PRO | 
|  |      9ragnaroks      2017-04-05 19:56:12 +08:00 更多的可能是上面要求 1 天内做完吧. 改 nginx 配置可能是最快的了. location /{ set $mob 'y'; if ($http_user_agent ~* "(Android|iPhone|Windows Phone)"){ set $mob "${mob}e"; } if ($host != 'm.exp.com'){ set $mob "${mob}s"; } if ($mob = "yes"){ rewrite ^/$ http://m.exp.com/$1 last; } include /mnt/clouddisk/sync/web/rewrite.conf; #rewrite end } | 
|  |      10ragnaroks      2017-04-05 19:58:19 +08:00 | 
|      11mingyun      2017-04-05 22:32:18 +08:00 @luojiyin87 nice 支持这么多语言 | 
|  |      12ryd994      2017-04-06 07:56:48 +08:00 via Android 怎么楼上都是用 if 和 rewrite 的呢……… 用 map 和 return 不好吗? | 
|  |      13shew2356      2017-04-06 09:54:47 +08:00 <script type="text/javascript"> var isIosFlatform = function() { return navigator.userAgent.match(/(iPad|iPhone)/) ? !0 : !1 }; var isAndroidFlatform = function() { return navigator.userAgent.match(/(Android)/) ? !0 : !1 }; var isMobile = function() { return isIosFlatform() || isAndroidFlatform() ? !0 : !1 }; if (!isMobile()) { window.location.href = "http://www.xxx.com/" } </script> | 
|  |      14assad OP 最后不得已,使用了 lua |