要在nginx中添加指定的Referer,您可以使用以下配置:

  1. 打开nginx配置文件(通常是/etc/nginx/nginx.conf/etc/nginx/conf.d/default.conf)。

  2. 在合适的位置添加以下代码:

location / {
    if ($http_referer !~* "指定的Referer") {
        return 403;
    }
    # 处理请求的其他指令
}

替换"指定的Referer"为您要允许访问的Referer网址。例如,如果您只允许example.comsubdomain.example.com访问,可以将代码替换为:

if ($http_referer !~* "example.com|subdomain.example.com") {
    return 403;
}
  1. 保存配置文件并重新加载nginx服务。
sudo service nginx reload

现在,如果请求的Referer不是指定的Referer,nginx将返回403 Forbidden状态码

nginx 添加指定的Referer

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

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