最近用Ngxin反向代理搭建了一个图站,怎么开启防盗链呢
nginx做反向代理真的非常简单,只需设置location+proxy_pass即可。
防盗链配置有些复杂,需要注意的地方:

server {
    listen  80;
    server_name hostname;     
    
    location / {
        location ~ .*\.(jpeg|jpg|gif|bmp|png)$ {
            valid_referers none blocked ~\.domain1\.com server_names ~\.domain2\.net; 
                if ($invalid_referer) {
                    return 403;
                }   
                proxy_pass  http://hostname;
            }     
 
        proxy_pass  http://hostname;
    }   
} 

设置完成之后如果在其他网站贴链接,就是下面↓这种结果,直接显示不出来,哈哈哈
sssssss

Last modification:June 2nd, 2020 at 02:09 pm
If you think my article is useful to you, please feel free to appreciate