关于nginx:Nginx区分移动PC端-响应不同页面

背景:


/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;
}

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理