我遇到下一个问题:
具有前端代理服务器,该服务器指向我的后端服务器。有人在通过我的图像偷带子,所以我想阻止这种情况的发生。我使用如下所示的proxy.conf文件:
server {
listen 80;
server_name site1.com www.site1.com;
server_name site2.com www.site2.com;
server_name site3.com www.site3.com;
server_name site4.com www.site4.com;
server_name site5.com www.site5.com;
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://IP-back-end-server.com;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
我试图将他的配置放在我的代理前端服务器上:
#hotlinking protection
location ~* \.(png|gif|jpg|jpeg)$ {
valid_referers none blocked site1.com www.site1.com;
valid_referers none blocked site2.com www.site2.com;
valid_referers none blocked site3.com www.site3.com;
valid_referers none blocked site4.com www.site4.com;
if ($invalid_referer){
return 403;
}
}
但是,结果所有图像都被阻止,包括我指向的域:site1.com site2.com site3.com site4.com
第二个选项,我试图在后端服务器上阻止真正的htaccess:
RewriteCond "%{HTTP_REFERER}" "!^$"
RewriteCond "%{HTTP_REFERER}" "!www.site1.com" [NC]
RewriteRule "\.(gif|jpg|png)$" "-" [F,NC]
结果,什么也没有发生,所有图像都显示为热链接。在这种情况下请帮助我。谢谢