Nginx 配置之图片防盗链
Nginx 防盗链 About 948 words配置
location ~* ^/uploads/img/.*?\.(jpe?g|png|gif|svg)$ {
valid_referers none blocked server_names ~($host);
if ($invalid_referer) {
return 403;
}
expires max;
root z_blog_openresty/resources/;
}
含义
第一行: jpe?g|png|gif|svg
表示对jpg
、jpeg
、png
、gif
后缀的文件进行防盗链判断
第二行: valid_referers
表示对Nginx
中$host
(网站域名)进行判断
第三行: if{}
如果不是指定Referer
就返回403
错误。
扩展
只限制 referer 不为空
location ~* ^/uploads/img/.*?\.(jpe?g|png|gif|svg)$ {
if ($http_referer ~ /^$/) {
return 403;
}
expires max;
root z_blog_openresty/resources/;
}
或者
location /data {
valid_referers ~.*;
if ($invalid_referer) {
return 403;
}
root /usr/share/nginx/html/;
}
location ~* ^/uploads/img/.*?\.(jpe?g|png|gif|svg)$ {
valid_referers ~.*;
if ($invalid_referer) {
return 403;
}
expires max;
root z_blog_openresty/resources/;
}
参考
Views: 2,581 · Posted: 2019-03-20
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...