joe2.0主题地址:https://bbchin.com/archives/halo-theme-joe20

原版nginx代码

1
2
3
4
5
6
7
8
9
10
11
# 资源防盗链(指定目录or指定文件类型)
# location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
location /upload/ {
access_log off;
# 域名白名单,去掉则阻止所有非本站请求
valid_referers none blocked server_names *.bbchin.com 127.0.0.1 localhost ~\.google\. ~\.baidu\. ~\.qq\.;
if ($invalid_referer) {
rewrite ^/ https://cdn.jsdelivr.net/gh/qinhua/cdn_assets/img/robber.jpg;
}
proxy_pass http://127.0.0.1:8090;
}

修改后的代码填入 Advanced

1
2
3
4
5
6
7
8
location ~ .*\.(webp|gif)$ {
access_log off;
valid_referers none blocked server_names *.macin.top ip地址 ~\.google\. ~\.baidu\. ~\.qq\.;
if ($invalid_referer) {
rewrite ^/ https://cdn.jsdelivr.net/gh/qinhua/cdn_assets/img/robber.jpg;
}
proxy_pass http://172.17.0.1:8090;
}

检验防盗链是否成功

https://www.bt.cn/bbs/forum.php?mod=post&action=reply&fid=36&tid=8827&cedit=yes

如果是用 Cloudflare 的 CDN 服务,那就无需设置 nginx 防盗链了,因为设置了也不会生效。在 Cloudflare 的 Scrape Shield 拉到最下面 Hotlink 保护打开即可防止站外链接指向您网站的图像