以下代码添加至站点配置conf文件的 server内,valid_referers none blocked后面为允许使用静态资源的域名,以英文空格分隔:

       location ~* \.(gif|jpg|png|jpeg|bmp|pdf|zip)$ {
	   expires     30d;
       valid_referers none blocked *.baidu.com *.google.com *.sogou.com;
	   if ($invalid_referer) {
	   #rewrite ^/ http://ww.yourdomain.com/images/404.jpg;盗链替代图片地址
	   return 404;
	    }
	   }

 

Centos+nginx 站点配置静态资源防盗链
https://fanly.net/article/bMjgu8ZDM1
转载请注明出处,谢谢!