nginx 添加指定的Referer
要在nginx中添加指定的Referer,您可以使用以下配置:
-
打开nginx配置文件(通常是
/etc/nginx/nginx.conf或/etc/nginx/conf.d/default.conf)。 -
在合适的位置添加以下代码:
location / {
if ($http_referer !~* "指定的Referer") {
return 403;
}
# 处理请求的其他指令
}
替换"指定的Referer"为您要允许访问的Referer网址。例如,如果您只允许example.com和subdomain.example.com访问,可以将代码替换为:
if ($http_referer !~* "example.com|subdomain.example.com") {
return 403;
}
- 保存配置文件并重新加载nginx服务。
sudo service nginx reload
现在,如果请求的Referer不是指定的Referer,nginx将返回403 Forbidden状态码
原文地址: https://www.cveoy.top/t/topic/iNhY 著作权归作者所有。请勿转载和采集!