Apache和Lighttpd防盗链规则

2013年12月4日

原创内容,转载请注明出处:https://www.myzhenai.com.cn/post/1652.html https://www.myzhenai.com/thread-16092-1-1.html
Apache防盗链规则的用法:在根目录下新建一个.htaccess文件,将以下规则内容复制到.htaccess文件里保存即可.然后

service httpd restart

 

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$ [NC]
RewriteCond %{HTTP_REFERER} !mybabya.com [NC]
RewriteCond %{HTTP_REFERER} !myzhenai.com [NC]
RewriteCond %{HTTP_REFERER} !myzhenai.com.cn [NC]
RewriteCond %{HTTP_REFERER} !google.com [NC]
RewriteCond %{HTTP_REFERER} !google.cn [NC]
RewriteCond %{HTTP_REFERER} !tianya.cn [NC]
RewriteCond %{HTTP_REFERER} !haikou-china.com [NC]
RewriteCond %{HTTP_REFERER} !0898-shop.com [NC]
RewriteRule .(JPG|JPEG|PNG|BMP|GIF|SWF|RAR|ZIP|jpge|jpg|png|bmp|jpeg|gif|swf|rar|zip|mp3|wmv|wav|wma|flv)
https://www.myzhenai.com.cn/myzhenai.gif [R,NC,L]

 
/* 我不知道能不能识别大小写的后缀名,所以我大小写都写上了. 后边的图片链接是当来路不是规则里允许的来路时自动跳转到的图片,需要绝对地址 */

Lighttpd防盗链规则的用法:分别在/etc/lighttpd/lighttpd.conf /home/lighttpd/conf/domains/domains.conf 规置文件里添加规则文件,然后

servcie lighttpd restart

 
即可.打开配置文件下的mod_access模块(找到这个,将前边的#号去掉保存就可以了.)
lighttpd官方的防盗链规则例子如下:

# deny access for all image stealers (anti-hotlinking for images)
  $HTTP["referer"] !~ "^($|https://www\.example\.org)" {
    url.access-deny = ( ".jpg", ".jpeg", ".png" )
  }

 

以下这个是我修改过后的防盗链规则,因为我有多个域名,所以需要多个域名之间共享.

$HTTP["referer"] !~ "^($|https://.*\.(mybabya\.com|myzhenai\.com|myzhenai\.com.cn|haikou-china\.com))" {
    url.access-deny = ( ".jpg",".jpeg",".png",".gif",".zip",".rar",".mp3",".mp4",".wmv",".mp2",".wma",".flv")
}

 

或者

$HTTP["referer"] !~ "^($|https://.*\.mybabya\.com)|($|https://.*\.myzhenai\.com)|($|https://.*\.myzhenai\.com.cn)|($|https://.*\.haikou-china\.com)" {
    url.access-deny = ( ".jpg",".jpeg",".png",".gif",".zip",".rar",".mp3",".mp4",".wmv",".mp2",".wma",".flv")
}

 

hostloc的圈圈曾说过,好像lighttpd的防盗链规则只能针对图片有效.对下载文件和音频视频文件需要额外安装什么软件,这些我没测试过,但我还是把它们加上了.万一有效了呢?
经过我测试,以上的规则都是有效的.


sicnature ---------------------------------------------------------------------
Your current IP address is: 44.193.80.126
Your IP address location: 美国弗吉尼亚阿什本
Your IP address country and region: 美国 美国
Your current browser is:
Your current system is:
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source http://myzhenai.com/post/1652.html

没有评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注