2020-11-10 | UNLOCK

Nginx 判断手机还是 PC

Nginx 判断是移动端还是手机端,两个端互相跳转

代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
upstream m_app_server {
server 0.0.0.0:9001;
}
server {
listen 80;
server_name m.264.cn;
root /path/to/mobile_site; # ...
location / {
proxy_set_header X-Real-IP $remote_addr; # ...
if ($http_user_agent ~* '(Android|webOS|iPhone|iPod|BlackBerry)') {
set $mobile_request '1';
}
if ($http_cookie ~ 'mobile_request=full') {
set $mobile_request '';
}
# 改这里
if ($mobile_request != '1') {
rewrite ^.+ http://www.264.cn$uri;
} # serve cached pages ...
if (!-f $request_filename) {
proxy_pass http://m_app_server;
break;
}
}
}

评论加载中