卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章68161本站已运行4217

nginx 配置文件设置 pc访问403 手机访问正常

        
# 定义一个变量用于标识是否允许访问  
    set $allow_access 0;  
  
    # 匹配手机User-Agent  
    if ($http_user_agent ~* "(Mobile|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|webOS|windows phone)") {  
        set $allow_access 1;  
    }  
    
    # 匹配搜索引擎爬虫User-Agent  
    if ($http_user_agent ~* (bingbot|YandexBot|Baiduspider|Sogou|360Spider|so.com|Sosospider|Bytespider|YisouSpider|Baiduspider-render|Baiduspider-video|Baiduspider-news|Baiduspider-mobile)) {  
        set $allow_access 1;  
    }  
    
# 匹配pc正常访问的目录,后台目录
    location /admin/{
       set $allow_access 1;  
    }
    
    location / {  
        # 检查是否允许访问  
        if ($allow_access = 0) {  
            # 如果不允许访问,返回403 Forbidden错误  
             return 403;
        }  
}
 
卓越飞翔博客
上一篇: nginx 配置文件设置文件不给缓存
下一篇: 返回列表

相关推荐

留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏