使用nginx可以直接截获客户端请求,以下是最近收集的一些判断截获的信息的配置,为查看方便记录如下:
1、根据UA和cookie判断当前是移动端还是PC端访问:
if ($http_host !~ “^www.weidao.com$”) {
rewrite ^(.*) http://www.test.com$1 permanent;
}
if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
rewrite ^(.*) http://m.test.com$1 permanent;
}
2、根据UA判断手机的操作系统:
if ($http_user_agent ~* “Android”) {
rewrite . http://m.baidu.com/ break;
}
if ($http_user_agent ~* “iPhone”) {
rewrite . http://m.baidu.com/ break;
}
if ($http_user_agent ~* “iPod”) {
rewrite . http://m.baidu.com/ break;
}
if ($http_user_agent ~* “iPad”) {
rewrite . http://m.baidu.com/ break;
}
if ($http_user_agent ~* “Windows Phone”) {
rewrite . http://m.baidu.com/ break;
}
if ($http_user_agent ~* “Mobile”) {
rewrite . http://m.baidu.com/ break;
}
if ($http_user_agent ~* “Nokia”) {
rewrite . http://m.baidu.com/ break;
}
if ($http_user_agent ~* “SAMSUNG”) {
rewrite . http://m.baidu.com/ break;
}
if ($http_user_agent ~* “HTC”) {
rewrite . http://m.baidu.com/ break;
}
if ($http_user_agent ~* “BlackBerry”) {
rewrite . http://m.baidu.com/ break;
}
if ($http_user_agent ~* “LG”) {
rewrite . http://m.baidu.com/ break;
}
if ($http_user_agent ~* “SonyEricsson”) {
rewrite . http://m.baidu.com/ break;
}
if ($http_user_agent ~* “MOT”) {
rewrite . http://m.baidu.com/ break;
}
if ($http_user_agent ~* “Opera Mini”) {
rewrite . http://m.baidu.com/ break;
}
if ($http_user_agent ~* “J2ME”) {
rewrite . http://m.baidu.com/ break;
}
if ($http_user_agent ~* “mqqbrowser”) {
rewrite . http://m.baidu.com/ break;
}
3、NG直接截获请求返回JSON:
location /api/Message/Confirm
{
default_type application/json;
return 200 ‘{“Data”:true,”Code”:1,”Message”:null}’;
}
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/2746.html