nginx安全配置 图片防盗链
#none允许referer为空
#blocked允许不带协议的请求
#仅允许referer为www.test.cn或test.cn
location /images/ {
valid_referers none blocked www.test.cn test.cn;
if ($invalid_referer) {
return 403;
}
}
可以给不符合referer规则的请求重定向到一个默认的图
location /images/ {
valid_referers blocked www.test.cn test.cn
if ($invalid_referer) {
rewrite ^/images/.*\.(gif|jpg|jpeg|png)$ /static/home.jpg last;
}
}