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