Nginx响应式访问配置

如果一个网站有PC和移动端两版,如何通过nginx来针对移动端和PC端访问响应不同的代码呢?

Nginx响应式访问配置

话不多说,直接上代码:

1
2
3
4
5
6
7
8
9
10
11
12

server{
listen 80;
server_name layout.onlyloveacat.com;
location / {
root /usr/share/nginx/pc; //pc端
if ($http_user_agent ~* '(Android|webOS|iPhone|iPod|BlackBerry)') {
root /usr/share/nginx/mobile; //移动端
}
index index.html;
}
}
扫一扫,请老师喝水