防盗链
防盗链主要作用就是避免站点资源被别人恶意滥用,包括静态资源以及接口资源。
图片防盗链
location ~* \.(gif|jpg|png|webp)$ {
valid_referers none blocked domain.com *.domain.com server_names ~\.google\. ~\.baidu\.;
if ($invalid_referer) {
return 403;
#rewrite ^/ http://www.domain.com/403.jpg;
}
root /opt/www/image;
}
接口防盗链
location = "/Project/getData.do" {
valid_referers demain.com.cn;
if ($invalid_referer) {
return 403;
}
client_max_body_size 100M;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://IP:8080;
access_log logs/access_project.log access_log_json;
}