防盗链技术现状: 1、通过识别Referer确认请求来源页面 2、Apache,squid等都能对Referer进行识别 3、通过ActiveX显示的内容不向服务器提供Referer Header(例如,Flash,WindowsMedia视频 等) 4、流媒体的RTSP协议也不向服务器提供Referer Header 5、通过服务器端程序代码实现 防盗链应用现状: 1、对图片、HTML等可以实现防盗链 2、无法对Flash,WindowsMedia视频 (MMS,RTSP)实现防盗链 3、服务器端程序代码实现的防盗链无法通过CDN加速 对于Flash,WindowsMedia视频 这种占用流量较大的服务无法实现防盗链,对一个依靠这类内容作为盈利点的网站来说是非常头疼的,俺通过一些研究以及测试实现了采用Cookie技术的防盗链解决方案,完美的解决了对Flash,WindowsMedia视频 的防盗链。 首先发现虽然ActiveX插件不传递Referer,但是却忠实的传递Cookie。于是在显示ActiveX的页面的<head> </head>标签内嵌入一段代码: <script> document.cookie=”Cache=vod;domain=domain.com;path=/”; </script> 这段代码用 javascript 设置了一段 Cookie: Cache=vod 然后通过各种ACL来判断这个Cookie的存在以及验证其值的操作了 参考文章:http://bbs.pcbeta.com/thread-308355-1-1.html 下面的是我网络上面找的文章
自然也要有Squid的防盗链。原理都一样,对Referer进行判断,当然网上有所谓的终极解决方案还对cookies进行判断的,这里还是只讨论Referer这种。在Squid里就是在配置文件添加acl控制,在squid.conf中的acl段添加如下配置:
acl has_referer referer_regex . acl allow_referer referer_regex -i baidu\.com acl allow_referer referer_regex -i google\.com acl allow_referer referer_regex -i yahoo\.cn acl allow_referer referer_regex -i google\.cn
http_access allow !has_referer http_access deny !allow_referer deny_info http://img1.test.com/images/noposter.jpg allow_referer
解释一下,has_referer匹配Referer存在,然后利用!has_referer来匹配没有Referer即直接访问的请求,这部分请 求不予做防盗链处理,allow。allow_referer即允许使用源站资源的网站,然后利用!allow_referer来匹配不在允许列表的网 站,这些不允许的Referer过来的请求就返回deny_info的内容
(按照上面的我在squid里面写完以后,导致只能百度这几个写了的访问,其他的一概都不能访问,这是放盗链的结果,可是还有问题我如果只是想给某一个域名设置防盗链这样的配置就不行了,这导致所有的域名都设置成这样的防盗链了。还有除了比如www.jiayuan.com这一个域名可以实现这个效果,而www.jiayuan.com/...后面的都被403禁止了。这可能是我那里设置的有问题。我还会在做实验去验证的。)下面是我的配置
acl manager proto cache_object acl localhost src 127.0.0.1 acl to_localhost dst 127.0.0.0/8 acl SSL_ports port 443 acl Safe_ports port 80 # http acl Safe_ports port 21 # ftp acl Safe_ports port 443 # https acl Safe_ports port 70 # gopher acl Safe_ports port 210 # wais acl Safe_ports port 1025-65535 # unregistered ports acl Safe_ports port 280 # http-mgmt acl Safe_ports port 488 # gss-http acl Safe_ports port 591 # filemaker acl Safe_ports port 777 # multiling http acl purge method purge
acl CONNECT method CONNECT acl d-domains1 dstdomain "/usr/local/squid271/etc/dstdomain.conf"(这里面放置的是域名) acl has_referer referer_regex . acl allow_referer referer_regex -i baidu\.com http_access allow !has_referer http_access deny !allow_referer acl jiayuan_url dstdomain www.jiayuan.com cache_peer 59.151.18.12 parent 80 0 no-digest no-query originserver name=jiayuan cache_peer_access jiayuan allow jiayuan_url cache_peer_access jiayuan deny all
squid防盗链的配置如下:
acl pics urlpath_regex -i \.(gif|jpg|jpeg|bmp|png)$ /* 匹配是否是图片 */ acl domain_refer referer_regex -i domain /* 匹配允许的域名关键字 */ acl notnull_refer referer_regex . /* 匹配非空referer */ http_access allow pics !notnull_refer /* 允许空referer访问图片 */ http_access deny pics !domain_refer /* 拒绝其他域名调用图片 */ deny_info http://www.domain.com/logo.gif domain_refer /* 有盗链的,显示我们的 logo*/
|