背景:
有
/www/wwwroot/example-h5
/www/wwwroot/example-pc
两个目录, 须要依据用户端, 响应不同的页面
解决方案
依据用户UA不同, 响应正确的页面给用户
# 默认响应挪动端动态资源set $root_dir /www/wwwroot/example-h5;# !~* 是一条正则表达式,!示意取反, ~*示意不辨别大小写 if ($http_user_agent !~* "(mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)") { # 非挪动端UA, 响应PC动态资源 set $root_dir /www/wwwroot/example-pc;}location / { # root 应用下面定义的变量 root $root_dir; try_files $uri $uri/ /index.html =404; #index index.html;}