<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[「实践ok」apache限速和限制IP连接数的模块---防刷积分，刷邀请好友。外加nginx同类插件：限制IP连接数，限速。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Sun, 05 Jun 2011 01:37:58 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	安装mod_bw 和 mod_limitipconn 都非常简单。<br/>1、下载：<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wget http://dominia.org/djao/limit/mod_limitipconn-0.22.tar.gz <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wget http://bwmod.sourceforge.net/files/mod_bw-0.7.tgz<br/>2.安装<br/>#tar -zxvf mod_limitipconn-0.22.tar.gz<br/>#cd mod_limitipconn-0.22<br/>#vi Makefile<br/>修改：apxs = “/usr/local/apache2/bin/apxs” # 这里是自己apache的apxs路径，加载模块<br/>或者<br/>#/usr/local/apache2/bin/apxs -i -c -a mod_limitipconn.c&nbsp;&nbsp;来加载模块<br/>#make<br/>#make install<br/>#tar -xvf mod_bw-0.7.tgz<br/>#cd mod_bw<br/>#/usr/local/apache2/bin/apxs -i -c -a /home/kenami/mod_bw/mod_bw.c<br/>下面用vi打开apache 的配置文件 httpd.conf<br/>发现了以下两行：<br/>LoadModule limitipconn_module modules/mod_limitipconn.so<br/>LoadModule bw_module&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;modules/mod_bw.so<br/>说明这两个模块安装成功<br/>以下在httpd.conf 配置这两个模块，我的配置如下：<br/>&lt;IfModule mod_limitipconn.c&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;Location /home/bo@znche.com/attachments/month_*&gt; #需要控制的路径<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MaxConnPerIP 3 #限制的线程数<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NoIPLimit index.htm #对此文件不做限制<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Location&gt;<br/>&lt;/IfModule&gt;<br/>在论坛的虚拟主机配置文件下面加上：<br/>&nbsp;&nbsp;&nbsp;&nbsp;BandwidthModule On&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;ForceBandWidthModule On<br/>&nbsp;&nbsp;&nbsp;&nbsp;Bandwidth all 10000 #限速10K<br/>&nbsp;&nbsp;&nbsp;&nbsp;MinBandwidth all -1<br/>测试了一下，一切正常，下载mp3的速度限制在10K一下，这样就再也不用担心大量的下载链接导致apache当机的问题了，当然以上方法不能阻止攻击。<br/><br/><br/>=====================<br/>使用mod_limitipconn模块为apache提供并发连接数控制<br/> <br/>2007-09-29 kenthy#qingdaonews.com<br/> <br/>##################################################################################<br/>系统环境：Red Hat Enterprise Linux Server release 5 (kernel 2.6.18-8.el5xen)<br/>软件环境：<br/>&nbsp;&nbsp;&nbsp;&nbsp;httpd-2.2.6.tar.bz2<br/>&nbsp;&nbsp;&nbsp;&nbsp;mod_limitipconn-0.22.tar.gz<br/> <br/>&nbsp;&nbsp;&nbsp;&nbsp;——参考下载地址：<br/>&nbsp;&nbsp;&nbsp;&nbsp;http://apache.mirror.phpchina.com/httpd/httpd-2.2.6.tar.bz2<br/>&nbsp;&nbsp;&nbsp;&nbsp;http://dominia.org/djao/limit/mod_limitipconn-0.22.tar.gz<br/> <br/>目标功能：<br/>&nbsp;&nbsp;&nbsp;&nbsp;通过增加扩展模块的方式，为apache服务器提供并发连接数控制<br/><br/>##################################################################################<br/>一、安装httpd及mod_limitipconn模块<br/>&nbsp;&nbsp;# tar jxvf httpd-2.2.6.tar.bz2 -C /usr/src/<br/>&nbsp;&nbsp;# tar zxvf mod_limitipconn-0.22.tar.gz -C /usr/src/<br/>&nbsp;&nbsp;# cd /usr/src/httpd-2.2.6<br/>&nbsp;&nbsp;# patch -p1 &lt; ../mod_limitipconn-0.22/apachesrc.diff<br/>&nbsp;&nbsp;# ./configure --enable-so --enable-forward&nbsp;&nbsp;&nbsp;&nbsp; //如需更多特性请参考“./configure --help”<br/>&nbsp;&nbsp;# ./buildconf<br/>&nbsp;&nbsp;# make &amp;&amp; make install<br/>&nbsp;&nbsp;# cd /usr/src/mod_limitipconn-0.22<br/>&nbsp;&nbsp;# PATH=/usr/local/apache2/bin:$PATH make install<br/> <br/>二、增加并发连接数控制<br/>&nbsp;&nbsp;# vi /usr/local/apache2/conf/httpd.conf<br/>LoadModule status_module modules/mod_status.so<br/>LoadModule limitipconn_module modules/mod_limitipconn.so<br/>ExtendedStatus On<br/>CustomLog /var/log/httpd/access_log common env=!LIMITIP<br/>&lt;IfModule mod_limitipconn.c&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;LocationMatch ~ &quot;&#92;.mp3$&quot;&gt;&nbsp;&nbsp;&nbsp;&nbsp; //匹配.mp3后缀的URL<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MaxConnPerIP 2<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/LocationMatch&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;LocationMatch ~ &quot;^http://&quot;&gt;&nbsp;&nbsp;&nbsp;&nbsp; //基于正则表达式的方式根据URL进行限制，此处匹配所有以&quot;http://&quot;的URL，忽略大小写<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MaxConnPerIP 10<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NoIPLimit image/*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//对图片不做限制<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OnlyIPLimit audio/mpeg video&nbsp;&nbsp;&nbsp;&nbsp;//仅对音频、视频等进行限制<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/LocationMatch&gt;<br/>&lt;/IfModule&gt;<br/>Proxy client tracking&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//此行用于检测代理服务器后的客户端IP地址<br/> <br/>四、测试<br/>… …<br/>… …<br/>===<br/><br/>apache<br/>要使apache服务器做对同一IP地址的连接限制，需要mod_limitipconn来实现。一般需要手动编译。不过模块作者也提供了一些编译好的模块，根据自己的apache版本可以直接使用。<br/>1。编译方式：<br/>tar zxvf mod_limitipconn-0.XX.tar.gz<br/>cd mod_limitipconn-0.XX<br/>make apxs=/usr/local/apache/bin/apxs —–这里要按你自己的路径设置<br/>make install apxs=/usr/local/apache/bin/apxs —–这里要按你自己的路径设置<br/>2.rpm安装方式：<br/>直接下载mod_limitipconn-0.xx.rpm<br/>rpm -Uhv mod_limitipconn-0.xx.rpm<br/>然后确认产生的mod_limitipconn.so文件在apache服务器模块目录里。<br/>3。编辑httpd.conf文件：<br/>ExtendedStatus On<br/>LoadModule limitipconn_module modules/mod_limitipconn.so &lt; IfModule mod_limitipconn.c &gt;<br/>&lt; Location / &gt; # 所有虚拟主机的/目录<br/>MaxConnPerIP 3 # 每IP只允许3个并发连接<br/>NoIPLimit image/* # 对图片不做IP限制<br/>&lt; /Location&gt;<br/>&lt; Location /mp3 &gt; # 所有主机的/mp3目录<br/>MaxConnPerIP 1 # 每IP只允许一个连接请求<br/>OnlyIPLimit audio/mpeg video # 该限制只对视频和音频格式的文件<br/>&lt; /Location &gt;<br/>&lt; /IfModule&gt;<br/>nginx<br/>nginx限制ip并发数，也是说限制同一个ip同时连接服务器的数量<br/>1.添加limit_zone<br/>这个变量只能在http使用<br/>vi /usr/local/nginx/conf/nginx.conf<br/>limit_zone one $binary_remote_addr 10m;<br/>2.添加limit_conn<br/>这个变量可以在http, server, location使用<br/>我只限制一个站点，所以添加到server里面<br/>vi /usr/local/nginx/conf/host/gaojinbo.com.conf<br/>limit_conn one 10;<br/>3.重启nginx<br/>killall nginx -HUP<br/>vi /usr/local/nginx/conf/vhosts/down.redocn.com.conf<br/>limit_zone one $binary_remote_addr 10m;<br/>server<br/>&#123;<br/>listen 80;<br/>server_name down.redocn.com;<br/>index index.html index.htm index.php;<br/>root /data/www/wwwroot/down;<br/>error_page 404 /index.php;<br/># redirect server error pages to the static page /50x.html<br/>error_page 500 502 503 504 /50x.html;<br/>location = /50x.html &#123;<br/>root html;<br/>&#125;<br/>#Zone limit<br/>location / &#123;<br/>limit_conn one 1;<br/>limit_rate 20k;//限速<br/>&#125;<br/># serve static files<br/>location ~ ^/(images&#124;javascript&#124;js&#124;css&#124;flash&#124;media&#124;static)/ &#123;<br/>root /data/www/wwwroot/down;<br/>expires 30d;<br/>&#125;<br/>&#125;<br/><br/><br/><br/><br/>来源：http://blogold.chinaunix.net/u1/40349/showart_392704.html<br/>Nginx参考自：http://www.cnblogs.com/amityat/archive/2011/08/23/2150168.html<br/><br/>Nginx进行限速处理<br/>限速使用 limit_zone, limit_conn 以及 limit_rate 进行配置<br/>首先在 http 段配置一个 limit_zone，然后在需要的地方使用 limit_conn 和 limit_rate 进行限速设置,如下一个简单的例子<br/><br/>http &#123;<br/>limit_zone one $binary_remote_addr 10m;<br/>server &#123;<br/>location /files/ &#123;<br/>limit_conn one 1;<br/>limit_rate 20k;<br/>&#125;<br/>&#125;<br/>&#125;<br/>说明:<br/>limit_zone，是针对每个IP定义一个存储session状态的容器。这个示例中定义了一个名叫one的10m大小的容器，这个名字会在后面的limit_conn中使用。<br/><br/>limit_conn one 1;<br/>限制在one中记录状态的每个IP只能发起一个并发连接。<br/><br/>limit_rate 20k;<br/>对每个连接限速20k. 注意，这里是对连接限速，而不是对IP限速。如果一个IP允许三个并发连接，那么这个IP就是限速为limit_rate×3，在设置的时候要根据自己的需要做设置调整，要不然会达不到自己希望的目的。<br/><br/>----------<br/><br/>官方参考：http://wiki.nginx.org/NginxHttpLimitZoneModule
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] 「实践ok」apache限速和限制IP连接数的模块---防刷积分，刷邀请好友。外加nginx同类插件：限制IP连接数，限速。]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>