Nginx防盗链模块ngx_http_referer_module

ngx_http_referer_module
⽤用来阻⽌止Referer⾸首部⽆无有效值的请求访问,可防⽌止盗链
指令:
12.1 valid_referers
定义 referer ⾸首部的合法可⽤用值,不不能匹配的将是
⾮非法值
Syntax: valid_referers none | blocked |
server_names | string …;`
Default: —
Context: server, location
参数:
none # 请求报⽂文⾸首部没有referer⾸首部
blocked # 请求报⽂文有referer⾸首部,但⽆无有
效值(防⽕火墙)
server_names # 参数,其可以有值作为主
机名或主机名模式
arbitrary_string # 任意字符串串,但可使
⽤用 * 作通配符
regular expression # 被指定的正则表达
式模式匹配到的字符串串,要使⽤用 ~ 开头,例例
如: ~.*.a.com
盗链
<body>
<iframe src="http://www.b.com/logo.j
pg"/> </iframe>
</body>
防⽌止盗链
server {
listen 80;
server_name www.b.com;
root /data/web2/ ;
valid_referers none block server
_names *.b.com b.* ~.*.google.com
; # 匹配到的都允许访问
if ($invalid_referer) { # 拒

return 403 ;
}
}

原文地址:https://www.cnblogs.com/momenglin/p/11107942.html