如果你CDN会缓存http 302状态的话,那么CDN就有可能会缓存防盗图,正常用户访问时会返回CDN中的”提示图”,而非正常图.
这里里解决方法是让rewrite后的302改成403状态.
nginx原配置
- location ~* ^.+\.(jpg|jpeg|gif|png|swf|rar|zip|css|js)$ {
- valid_referers none blocked *.c1gstudio.com localhost cache.baiducontent.com c.360webcache.com www.sogou.com cc.bingj.com;
- if ($invalid_referer) {
- rewrite ^/ http://leech.c1gstudio.com/leech.gif;
- return 412;
- break;
- }
- access_log off;
- root /opt/lampp/htdocs/c1gstudio;
- expires 3d;
- break;
- }
新的nginx配置
做一个代理到虚似主机
- upstream leech_server {
- server 192.168.0.75:80;
- }
- location @leech {
- proxy_set_header Host leech.c1gstudio.com;
- proxy_pass http://leech_server;
- }
- location ~* ^.+\.(jpg|jpeg|gif|png|swf|rar|zip|css|js)$ {
- valid_referers none blocked *.c1gstudio.com localhost cache.baiducontent.com c.360webcache.com www.sogou.com cc.bingj.com;
- if ($invalid_referer) {
- #rewrite ^/ http://leech.c1gstudio.com/leech.gif;
- error_page 412 = @leech;
- return 412;
- break;
- }
- access_log off;
- root /opt/lampp/htdocs/c1gstudio;
- expires 3d;
- break;
- }
- server
- {
- listen 80;
- server_name leech.c1gstudio.com;
- index index.html index.htm index.php;
- root /opt/lampp/htdocs/transfer_url;
- error_page 404 =403 /leech.gif;
- access_log off;
- location ~* ^.+\.(jpg|jpeg|gif|png)$ {
- access_log off;
- root /opt/lampp/htdocs/transfer_url;
- add_header Cache-Control no-cache;
- add_header Pragma no-cache;
- add_header Expires 0;
- break;
- }
- location ~/\.ht {
- deny all;
- }
- }
No Responses (yet)
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.