
Nginx 怎么配置根据 User-Agent 跳转到不通地址
比如,跳转到移动端的网站
我怎么配都跳转不过去
1 willakira 2017 年 4 月 5 日 强烈不推荐这么做,如果是用于生产环境的话 Nginx 、 apache 、 tomcat 这些 server 的配置一般不是由开发来管理的,因此 - 每次更新的时候都需要运维参与 - 出现问题的时候回滚非常麻烦 - 性能倒是其次, debug 会非常复杂 一般都会在 container 跑个小程序做这个,好处有 - 自己更新 - 出问题了自己回滚 - 容易 debug 把难以监控,不透明的东西做的简单,复杂的东西做的透明,就是这样 |
2 sundong 2017 年 4 月 5 日 ## 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; } |
3 luojiyin87 2017 年 4 月 5 日 |
4 chuhemiao 2017 年 4 月 5 日 直接上代码不好吗,干吗要 nginx 配置, php 扩展有手机类型,直接判断了,然走那就走那 |
5 SourceMan 2017 年 4 月 5 日 前端、后端做,都轮不到运维做。。。 |
6 prasanta 2017 年 4 月 5 日 现在网站直接响应式了 |
7 Cabana 2017 年 4 月 5 日 via Android 咋不做响应式呢 |
9 ragnaroks 2017 年 4 月 5 日 更多的可能是上面要求 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 } |
10 ragnaroks 2017 年 4 月 5 日 |
11 mingyun 2017 年 4 月 5 日 @luojiyin87 nice 支持这么多语言 |
12 ryd994 2017 年 4 月 6 日 via Android 怎么楼上都是用 if 和 rewrite 的呢……… 用 map 和 return 不好吗? |
13 shew2356 2017 年 4 月 6 日 <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> |
14 assad OP 最后不得已,使用了 lua |