# 定义一个变量用于标识是否允许访问
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 配置文件设置 pc访问403 手机访问正常
相关推荐
标签:
留言与评论(共有 0 条评论) |