防盗链主要用在资源站或文件服务器上,不想让别的网站引用你的资源,避免服务器流量浪费
Minio防盗链配置
location / {
# 防盗链 白名单
valid_referers none blocked server_names 4xx.me *.4xx.me 127.0.0.1 ~\.google\. ~\.baidu\. ~\.qq\. ~\.bing\. ~\.soso\. ~\.so\. ~\.sm\. ~\.youdao\. ~\.sogou\.;
set $flag 1;
if ($invalid_referer) {
set $flag 0;
}
# 正则表达式匹配
if ($request_uri ~* "(/logo.ico)|(/image.jpg)") {
set $flag 1;
}
if ($flag = 0) {
rewrite ^/ https://cdn.jsdelivr.net/gh/qinhua/cdn_assets/img/robber.jpg;
}
proxy_pass http://minio:9000;
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
- 支持排除源站地址
- 支持排除常见搜索引擎
- 支持排除指定资源链接