eygle.com   eygle.com
eygle.com  
 

« 从网易Q1财报 看网易的高瞻远瞩 | Blog首页 | 我的写作进度之三-初稿完成 »

如何配置Apache 防止图片盗链

作者:eygle |【转载时请务必以超链接形式标明文章和作者信息及本声明
链接:

最近这几天,网站的流量猛增,分析了一下,发现是自己收集的一些喜爱的图片遭到疯狂盗链,我很高兴有同样的朋友欣赏我的选择,可是流量实在大得我无法忍受.

这是昨天一天的数据:

SQL> select * from (
2 select c7 file_name,count(*) t
3 from eygle2 group by c7 order by t desc)
4 where rownum <31
5 /

FILE_NAME T
------------------------------ ----------
/me/Life.Is/372527349.jpg 5197
/me/Life.Is/677245005.jpg 5103
/me/Life.Is/622883788.jpg 5099
/me/Life.Is/602643161.jpg 5096
/me/Life.Is/681154946.jpg 5096
/me/Life.Is/670021057.jpg 5089
/me/Life.Is/697701797.jpg 5066
/me/Life.Is/993607765.jpg 5062
/me/Life.Is/734274457.jpg 5061
/me/Life.Is/874618979.jpg 5050
/me/Life.Is/592064176.jpg 5048
/me/Life.Is/593285462.jpg 5045
/me/Life.Is/622106024.jpg 5038
/me/Life.Is/821215868.jpg 5025
/me/Life.Is/581927270.jpg 5022
.............
/me/Life.Is/535733946.jpg 4878

30 rows selected

SQL>

查一下来源,发现主要盗链来自chinaren,baidu贴吧和腾讯:

SQL> select * from (
2 select c11,count(*) t from eygle2 where c11 not like '%itpub%'
3 group by c11 order by t desc ) where rownum <21
4 /

C11 T
------------------------------------------------ ----------
"http://club.chinaren.com/47108524.html" 243097
"http://club.chinaren.com/47210360.html" 118176
"http://club.chinaren.com/47209630.html" 46329
"http://club.chinaren.com/47209603.html" 13875
"http://club.chinaren.com/47209464.html" 8835
....
"http://imgcache.qq.com/qzone/blog/blog.html" 1769
"http://post.baidu.com/f?kz=100212679" 1361

20 rows selected

没办法马上采取措施,防止盗链,以下是从网上找到的方法,经测试有效:

1、假设允许连结图片的主机域名为:www.eygle.com
2、修改httpd.conf,增加如下配置

SetEnvIfNoCase Referer "^http://www.eygle.com/" local_ref=1

Order Allow,Deny
Allow from env=local_ref

这个简单的应用不光可以解决图片盗链的问题,稍加修改还可以防止任意文件盗链下载的问题。

使用以上的方法当从非指定的主机连结图片时,图片将无法显示,如果希望显示一张“禁止盗链”的图片,我们可以用mod_rewrite 来实现。

首先在安装 apache 时要加上 --enable-rewrite 参数加载 mod_rewrite 模组。

假设“禁止盗链”的图片为www.eygle.com.gif,我们在 httpd.conf 中可以这样配置:


RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.eygle.com/.*$ [NC]
RewriteRule \.(jpg|jpg)$ http://www.eygle.com/www.eygle.com.gif [R,L]


当主机的图片被盗链时,只会看到 www.eygle.com.gif 这张图片!

很抱歉要采取这样的手段.因为带宽实在是不允许.

希望没有影响到大家,对于善意的引用,请大家告诉我网站,我会取消相应的限制.

 

By eygle on 2006-05-18 10:12 | Comments (1) | Posted to Web | Edit |Pageviews:

相关文章 随机文章
  • 落后的技术就是灾难
  • What's Mean "internal dummy connection"?
  • Resin、Apache、PHP与404错误
  • 百度 城管 与 GFW
  • Eygle.Com网站统计信息
  • 如何使用sqlldr的WHEN判断加载数据到不同的数据表
    《深入浅出Oracle》出版一月记
    DBA警世录:职业生涯误操作之误删除篇
    关于HDS的高端存储设备USPV
    2008 新年快乐
    网上相关主题:
    Google

    留言 (1)

    我也配置了,还做了rewrite转向回原作地址。

    Posted by: Che Dong at December 4, 2006 5:55 PM

    发表留言:



    Remember Me?
    (输入验证码后方可评论,谢谢支持)



    CopyRight © 2004 eygle.com, All rights reserved.