« »
2007-11-24Apache

78

apache优化列表

apache限制ip连接数

首先,执行

#apt-get install libapache-mod-limitipconn

然后nano /etc/apache/httpd.conf
先找到这一行
#ExtendedStatus On

查看是否被注释了,如果是的话,去掉注释

再查找这个字符串mod_limitipconn.so
如果没找到任何记录,就在任何位置添加以下一行

LoadModule limitipconn_module modules/mod_limitipconn.so

然后就可以做限制了

对全局进行限制的话,就直接加入

 <IfModule mod_limitipconn.c>
  <Location />
   MaxConnPerIP 3            #每ip最多3个连接
   NoIPLimit image/*         #对图片不限制
  </Location>
 </IfModule>
如果你只想设置某个虚拟主机的连接限制,就把上面的那段放入

<VirtualHost>

</VirtualHost>

之中

如果只想限制某个目录的文件就可以这样

  <Location /mp3>
MaxConnPerIP 1  #限制1个连接
# In this case, all MIME types other than audio/mpeg and video*
# are exempt from the limit check
OnlyIPLimit audio/mpeg video  #只限制audio/mpeg video文件,如MP3呀WMA呀这种文件后缀名
    </Location>

修改apache最大连接数

 

# prefork MPM
# StartServers ……… number of server processes to start
# MinSpareServers …… minimum number of server processes which are kept spare
# MaxSpareServers …… maximum number of server processes which are kept spare
# MaxClients ……….. maximum number of server processes allowed to start
# MaxRequestsPerChild .. maximum number of requests a server process serves
<IfModule prefork.c>
StartServers         5
MinSpareServers      5
MaxSpareServers     10
MaxClients          20
MaxRequestsPerChild  0
</IfModule>

# pthread MPM
# StartServers ……… initial  number of server processes to start
# MaxClients ……….. maximum  number of server processes allowed to start
# MinSpareThreads …… minimum  number of worker threads which are kept spare
# MaxSpareThreads …… maximum  number of worker threads which are kept spare
# ThreadsPerChild …… constant number of worker threads in each server process
# MaxRequestsPerChild .. maximum  number of requests a server process serves
<IfModule worker.c>
StartServers         2
MaxClients         150
MinSpareThreads     25
MaxSpareThreads     75
ThreadsPerChild     25
MaxRequestsPerChild  0
</IfModule>

注意,如果不知道自己的apache2使用哪种工作模式,最简单的方法,先restart一下apache2,然后netstat -t 看看有几个apache2的进程,然后对比一下就可以了

ps:

apache2默认最大256连接,如果需要更大,自己手动编译

您还可能感兴趣的内容

日志信息 »

该日志于2007-11-24 01:13由 x72 发表在Apache分类下, 通告目前不可用,你可以至底部留下评论。

没有评论

发表评论 »


返回顶部