<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Windix's Blog &#187; apache</title>
	<atom:link href="http://douzi.org/wp/category/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://douzi.org/wp</link>
	<description>God only helps ones who help themselves</description>
	<lastBuildDate>Fri, 12 Jun 2009 10:25:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>打响下载专项治理第一枪</title>
		<link>http://douzi.org/wp/2006/01/09/%e6%89%93%e5%93%8d%e4%b8%8b%e8%bd%bd%e4%b8%93%e9%a1%b9%e6%b2%bb%e7%90%86%e7%ac%ac%e4%b8%80%e6%9e%aa/</link>
		<comments>http://douzi.org/wp/2006/01/09/%e6%89%93%e5%93%8d%e4%b8%8b%e8%bd%bd%e4%b8%93%e9%a1%b9%e6%b2%bb%e7%90%86%e7%ac%ac%e4%b8%80%e6%9e%aa/#comments</comments>
		<pubDate>Mon, 09 Jan 2006 01:08:01 +0000</pubDate>
		<dc:creator>windix</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[apache]]></category>

		<guid isPermaLink="false">http://www.douzi.org/wp/index.php/articles/166</guid>
		<description><![CDATA[提供锵锵三人行podcast以来，流量虽增加很多，但一直还维持正常水平，但最近几日突然增加了数倍，而且从awstats的统计日志中还可看到有极大数量的&#8221;Not viewed traffic(不可见流量)&#8221;，经查这部分主要是服务器响应为&#8221;206 Partial Content&#8221;的多线程下载流量。再这么下去，势必影响正常使用者的使用和服务器的其它功能。于是，我打响了下载专项治理的第一枪。
通过分析服务器日志，本次打击目标为以下两个：
1.严厉打击baidu mp3盗连现象
特征:
HTTP refer中包含&#8221;mp3.baidu.com&#8221;和&#8221;m?ct=&#8221;关键字。(前者为baidu的mp3索引爬虫，后者为实际的下载连接)
baidu真是猛，从它过来的mp3下载流量占到总量的80%以上，而且大部分人都使用多线程下载(最多的我还看到同时使用15个线程的)。
还好之前复习过了.htaccess文件的用法，现在一个文件就把baidu搞定了:
RewriteEngine on
RewriteCond %{HTTP_REFERER} mp3\\.baidu\\.com [NC,OR]
RewriteCond %{HTTP_REFERER} m\\?ct=
RewriteRule .* - [F]
2.严厉打击使用过多线程同时下载现象
我提供的这个服务主要是为了方便朋友们订阅podcast，所以不管是通过iTunes订阅还是通过podlook在线听的朋友都不会像上面提到那位用15个线程同时下载一个文件的(忘了说，他还同时下载两个文件呢)。其实大家都宽带了，使用单线程下载不会比15个线程慢多少，而且能够减轻服务器的负担，是对其他用户的一个最起码的尊重。
我使用了针对Apache 2的mod_limitipconn模块来限制单一IP的mp3文件的并发下载数为2。
安装很简单，大家可以参考这篇: Linux下Apache并发连接数和带宽控制。把相关的配置加在httpd.conf的虚拟主机部分就起作用了:
#### www.douzi.org ##############################
&#60;VirtualHost 219.149.56.157&#62;
   DocumentRoot /usr/wwwroot/douzi/html
   ServerAdmin admin@douzi.org
   DirectoryIndex index.html index.php
   ServerName www.douzi.org
   ServerAlias douzi.org
   ErrorLog /var/log/httpd/douzi/error_log
   CustomLog "&#124;/usr/bin/cronolog /var/log/httpd/douzi/access_log.%Y%m%d" combined
   HostNameLookups [...]]]></description>
			<content:encoded><![CDATA[<p>提供锵锵三人行podcast以来，流量虽增加很多，但一直还维持正常水平，但最近几日突然增加了数倍，而且从awstats的统计日志中还可看到有极大数量的&#8221;Not viewed traffic(不可见流量)&#8221;，经查这部分主要是服务器响应为&#8221;206 Partial Content&#8221;的多线程下载流量。再这么下去，势必影响正常使用者的使用和服务器的其它功能。于是，我打响了下载专项治理的第一枪。</p>
<p>通过分析服务器日志，本次打击目标为以下两个：</p>
<p>1.严厉打击baidu mp3盗连现象</p>
<p>特征:<br />
HTTP refer中包含&#8221;mp3.baidu.com&#8221;和&#8221;m?ct=&#8221;关键字。(前者为baidu的mp3索引爬虫，后者为实际的下载连接)</p>
<p>baidu真是猛，从它过来的mp3下载流量占到总量的80%以上，而且大部分人都使用多线程下载(最多的我还看到同时使用15个线程的)。</p>
<p>还好之前复习过了.htaccess文件的用法，现在一个文件就把baidu搞定了:</p>
<pre><code>RewriteEngine on
RewriteCond %{HTTP_REFERER} mp3\\.baidu\\.com [NC,OR]
RewriteCond %{HTTP_REFERER} m\\?ct=
RewriteRule .* - [F]</code></pre>
<p>2.严厉打击使用过多线程同时下载现象</p>
<p>我提供的这个服务主要是为了方便朋友们订阅podcast，所以不管是通过iTunes订阅还是通过podlook在线听的朋友都不会像上面提到那位用15个线程同时下载一个文件的(忘了说，他还同时下载两个文件呢)。其实大家都宽带了，使用单线程下载不会比15个线程慢多少，而且能够减轻服务器的负担，是对其他用户的一个最起码的尊重。</p>
<p>我使用了针对Apache 2的<a href="http://dominia.org/djao/limitipconn2.html">mod_limitipconn</a>模块来限制单一IP的mp3文件的并发下载数为2。</p>
<p>安装很简单，大家可以参考这篇: <a href="http://www.thinkjam.org/zoptuno/archives/2004/08/linuxaeapachee.html">Linux下Apache并发连接数和带宽控制</a>。把相关的配置加在httpd.conf的虚拟主机部分就起作用了:</p>
<pre><code>#### www.douzi.org ##############################
&lt;VirtualHost 219.149.56.157&gt;
   DocumentRoot /usr/wwwroot/douzi/html
   ServerAdmin admin@douzi.org
   DirectoryIndex index.html index.php
   ServerName www.douzi.org
   ServerAlias douzi.org
   ErrorLog /var/log/httpd/douzi/error_log
   CustomLog "|/usr/bin/cronolog /var/log/httpd/douzi/access_log.%Y%m%d" combined
   HostNameLookups off

   &lt;Directory "/usr/wwwroot/douzi/html"&gt;
      AllowOverride All
   &lt;/Directory&gt;

   <strong>&lt;IfModule mod_limitipconn.c&gt;
        &lt;Location /podcast/srx&gt;
                MaxConnPerIP 2
                OnlyIPLimit audio/mpeg
        &lt;/Location&gt;
    &lt;/IfModule&gt;</strong>

&lt;/VirtualHost&gt;</code></pre>
<p>另外提醒一句，不要忘记打开前面的&#8221;ExtendedStatus On&#8221;，这样这个模组才会起作用。</p>
]]></content:encoded>
			<wfw:commentRss>http://douzi.org/wp/2006/01/09/%e6%89%93%e5%93%8d%e4%b8%8b%e8%bd%bd%e4%b8%93%e9%a1%b9%e6%b2%bb%e7%90%86%e7%ac%ac%e4%b8%80%e6%9e%aa/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
