Nginx 根据访问终端跳转页面

有些需求需要同一个域名识别终端来展示不同的界面,使用Nginx获取UA来判断终端类型,实现简单的跳转操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
server {
 server_name g3.tm-sp.com;
 listen 80;
 access_log off;
 location / {
 if ($http_user_agent ~ "((MIDP)|(WAP)|(UP.Browser)|(Smartphone)|(Obigo)|(Mobile)|(AU.Browser)|(wxd.Mms)|(WxdB.Browser)|(CLDC)|(UP.Link)|(KM.Browser)|(UCWEB)|(SEMC\-Browser)|(Mini)|(Symbian)|(Palm)|(Nokia)|(Panasonic)|(MOT)|(SonyEricsson)|(NEC)|(Alcatel)|(Ericsson)|(BENQ)|(BenQ)|(Amoisonic)|(Amoi)|(Capitel)|(PHILIPS)|(SAMSUNG)|(Lenovo)|(Mitsu)|(Motorola)|(SHARP)|(WAPPER)|(LG)|(EG900)|(CECT)|(Compal)|(kejian)|(Bird)|(BIRD)|(G900/V1.0)|(Arima)|(CTL)|(TDG)|(Daxian)|(DAXIAN)|(DBTEL)|(Eastcom)|(EASTCOM)|(PANTECH)|(Dopod)|(Haier)|(HAIER)|(KONKA)|(KEJIAN)|(LENOVO)|(Soutec)|(SOUTEC)|(SAGEM)|(SEC)|(SED)|(EMOL)|(INNO55)|(ZTE)|(iPhone)|(Android)|(Windows CE)|(Wget)|(Java)|(curl)|(Opera))"){
	rewrite ^/(.*)$ http://221.180.20.228:8081/wap/$1 ;
}
if ( $http_user_agent ~ ^$ )  {  
	rewrite ^/(.*)$ http://221.180.20.228:8081/wap/$1 ;  
}         
 proxy_pass http://221.180.20.228:8080;
 }
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注