http://www.alixixi.com/web/a/2015070495008.shtml
server {
listen 80;
set $mobile_rewrite do_not_perform;
if ($http_user_agent ~* "(androidbb\d+meego).+mobileavantgobada\/blackberryblazercompalelainefennechiptopiemobileip(honeod)iriskindlelge maemomidpmmpmobile.+firefoxnetfrontopera m(obin)ipalm( os)?phonep(ixire)\/pluckerpocketpspseries(46)0symbiantreoup\.(browserlink)vodafonewapwindows cexdaxiino") {
set $mobile_rewrite perform;
}
if ($http_user_agent ~* "^(1207631065903gso4thp50[1-6]i770s802sa waabacac(eroos\-)ai(korn)al(avcaco)amoian(exnyyw)aptuar(chgo)as(teus)attwau(di\-mr s )avanbe(ckllnq)bi(lbrd)bl(acaz)br(ev)wbumbbw\-(nu)c55\/capiccwacdm\-cellchtmcldccmd\-co(mpnd)crawda(itllng)dbtedc\-sdevidicadmobdo(cp)ods(12\-d)el(49ai)em(l2ul)er(ick0)esl8ez([4-7]0oswaze)fetcfly(\-_)g1 ug560genegf\-5g\-mogo(\.wod)gr(adun)haiehcithd\-(mpt)hei\-hi(ptta)hp( iip)hs\-cht(c(\- _agpst)tp)hu(awtc)i\-(20goma)i230iac( \-\/)ibroideaig01ikomim1kinnoipaqirisja(tv)ajbrojemujigskddikejikgt( \/)klonkpt kwc\-kyo(ck)le(noxi)lg( g\/(klu)5054\-[a-w])libwlynxm1\-wm3gam50\/ma(teuixo)mc(0121ca)m\-crme(rcri)mi(o8oats)mmefmo(0102bidedot(\- ov)zz)mt(50p1v )mwbpmywan10[0-2]n20[2-3]n30(02)n50(025)n7(0(01)10)ne((cm)\-ontfwfwgwt)nok(6i)nzpho2imop(tiwv)oranowg1p800pan(adt)pdxgpg(13\-([1-8]c))philpirepl(ayuc)pn\-2po(ckrtse)proxpsiopt\-gqa\-aqc(0712213260\-[2-7]i\-)qtekr380r600raksrim9ro(vezo)s55\/sa(gemammmsnyva)sc(01h\-oop\-)sdk\/se(c(\-01)47mcndri)sgh\-sharsie(\-m)sk\-0sl(45id)sm(alarb3itt5)so(ftny)sp(01h\-v\-v )sy(01mb)t2(1850)t6(001018)ta(gtlk)tcl\-tdg\-tel(im)tim\-t\-moto(plsh)ts(70m\-m3m5)tx\-9up(\.bg1si)utstv400v750verivi(rgte)vk(405[0-3]\-v)vm40vodavulcvx(52536061708081838598)w3c(\- )webcwhitwi(g ncnw)wmlbwonux700yas\-yourzetozte\-)") {
set $mobile_rewrite perform;
}
if ($http_cookie ~ "gotopc=true") {
set $mobile_rewrite do_not_perform;
}
location / {
proxy_pass http://192.168.20.1; # 电脑版
if ($mobile_rewrite = perform) {
proxy_pass http://192.168.20.2; # 手机版
}
}
}
1
lhbc 2016-11-27 14:08:33 +08:00 via iPhone 1
楼主,用这么多 if 很不好啊
你应该用 map ,将 useragent 映射到 upstream ,这样不需要任何 if 即可。 |
2
shierji 2016-11-27 14:22:18 +08:00 via Android
if is evil
|
3
KingsWay 2016-11-27 14:45:52 +08:00
meego 。。。
|
4
ssvodown OP @lhbc 刚开始接触 nginx ,见笑了,本身对 nginx 的语法还不很了解, map 的用法写不出来,能详述下吗?
|
5
lhbc 2016-11-27 22:10:33 +08:00 1
@ssvodown
http 段配置: http { map $http_user_agent $platform { default pc; ~android mobile; ~iphone mobile; } } server 段配置: upstream www.example.com_pc { server 192.168.20.1; } upstream www.example.com_mobile { server 192.168.20.2; } server { listen 80; location / { proxy_pass http://www.example.com_$platform; } } |