纳速健身

标题: Apache下利用mod_rewrite防盗链 [打印本页]

作者: awagink    时间: 2008-3-29 10:36
标题: Apache下利用mod_rewrite防盗链
最近发现服务器的流量猛增,打开网页速度很慢,查看了一下Apache的log,发现:
166.111.208.185 - - [18/Dec/2007:22:27:55 +0800] “GET /music/tea.mp3 HTTP/1.1″ 206 2120152
166.111.208.185 - - [18/Dec/2007:22:27:56 +0800] “GET /music/tea.mp3 HTTP/1.1″ 206 2025202
166.111.208.185 - - [18/Dec/2007:22:27:56 +0800] “GET /music/tea.mp3 HTTP/1.1″ 206 757441
59.70.246.42 - - [18/Dec/2007:22:27:57 +0800] “GET /music/tea.mp3 HTTP/1.1″ 206 3012532
59.70.246.42 - - [18/Dec/2007:22:27:58 +0800] “GET /music/tea.mp3 HTTP/1.1″ 206 2809812
59.70.246.42 - - [18/Dec/2007:22:28:00 +0800] “GET /music/tea.mp3 HTTP/1.1″ 206 3033136
59.70.246.42 - - [18/Dec/2007:22:28:00 +0800] “GET /music/tea.mp3 HTTP/1.1″ 206 3036570
原来是因为服务器上的mp3文件被盗链了或者被迅雷这类的下载软件当成了种,被别人多线程下载,造成带宽被占,Apache响应不过来。
在网上找了一下,发现利用mod_rewrite模块就可以很好的完成Apache 的防盗链。
1. 在httpd.conf中加载mod_rewrite模块:
2. 在music目录下新建一个.htaccess文件
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?xmulib\.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://210.34.4.17/.*$ [NC]
RewriteRule \.(mp3|jpg)$ http://www.xmulib.net [R,NC]
#RewriteLog “logs/rewrite.log”
#RewriteLogLevel 3
参数说明:





欢迎光临 纳速健身 (https://nasue.com/) Powered by Discuz! X3.4