以下 Nginx 代码使用 map 语句,仅允许特定域名包含 'qyuc' 的 User-Agent 访问:

map $http_user_agent $allow_access {
    default 0;
    '~*qyuc' 1;
}

server {
    listen 80;
    server_name example.com; # 将 example.com 替换为你所需的特定域名

    if ($allow_access = 0) {
        return 403;
    }

    # 其他 server 配置
    # ...
}

将以上代码添加到宝塔面板中的 Nginx 配置文件,位置应该在 server 块内部。具体位置视你的配置文件而定,一般是在 server_name 后面添加即可。

Nginx 限制特定域名访问:仅允许包含 'qyuc' 的 User-Agent

原文地址: https://www.cveoy.top/t/topic/nwE7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录