我遇到了下一个问题:
有指向后端服务器的前端代理服务器。有人正在窃取我的图片带宽,所以我想阻止这种情况发生。我使用如下所示的 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]
结果什么都没发生,所有图片都显示为盗链。请帮我解决这种情况。谢谢