≮六づ道≯的Blog

天行键,君子以自强不息! & 路漫漫其修远兮,吾将上下而求索!

黄殿瑶ID:feel8
186952次访问,排名350(1)好友0人,关注者1
feel8的文章
原创 195 篇
翻译 0 篇
转载 1 篇
评论 100 篇
六道的公告
远离3721,还我一片静土!
 ╲█◤
◢██◣
   ◤◥
临渊羡鱼不如退而结网苦练内功ING -_-!!

昵称:≮六づ道≯
Mail:PHP5@QQ.COM
留言:点击留言




今日天气

最近评论
psnccs:WoW Gold
psnccs:WoW Gold
Eeeethan:不好意思,我想請教一個關於編譯Apache過濾器範例的問題,可能很初級,不過我確實找不到解答。我的問題是:
想請問怎麼要在Linux下用Gcc編譯:
httpd-2.2.4\modules\experimental\
裡的mod_case_filter.c
我下了
gcc -fPIC -I$../../include -c mod_case_……
风云★小子:一名刚学生!
你的时钟代码是什么啊?
南京甜蜜爱成人用品商城:<b>南京最大的零售、批发、加盟成人用品、性用品的网站[www.honey025.com],2000多种产品任您选购,1766个县市货到付款、3重

包装保密邮寄,主营:成人用品、性用品、性保健品、避孕用品、情趣内衣、壮阳药、阴茎增大丸、SM用品、安全套、男女自慰性器

具等</b><p>
[url=http://w……
文章分类
收藏
    相册
    我的相册
    My Links
    ChinaUNIX
    CSDN论坛
    Fedora官方网站
    LinuxEden
    LinuxSir
    mySQL官方网站
    PHP官方网站
    SmartTemplate
    中国赢网
    落伍者论坛
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 apache限制并发数,IP,带宽设置收藏

    新一篇: Apache 实现禁止图片盗链 | 旧一篇: 程序员的“素质”是什么?

    apache限制并发数,IP,带宽设置

    限制并发数
    下载模块:

    到官方网址: http://www.nowhere-land.org/programs/mod_vhost_limit/下载模块

    http://www.nowhere-land.org/programs/mod_vhost_limit/mod_vhost_limit-0.4.tar.gz

    安装:
    apxs -c mod_vhost_limit.c -o /path/to/libexec/mod_vhost_limit.so

     httpd.conf 加入:

    LoadModule vhost_limit_module libexec/mod_vhost_limit.so
    AddModule mod_vhost_limit.c

    配置:

    MaxClients 150
    ExtendedStatus On

    NameVirtualHost *

    <VIRTUALHOST * />
        ServerName       server1
        DocumentRoot     /some/where/1
        MaxVhostClients  100


    <VIRTUALHOST * />
        ServerName       server2
        DocumentRoot     /some/where/2
        MaxVhostClients  30


    <VIRTUALHOST * />
        ServerName       server3
        DocumentRoot     /some/where/3


    其中: server1 被限制为 100 个并发线程数。 server2 被限制为 30 个并发线程数。 server3 没有被限制。

    注:需 mod_status  ExtendedStatus On 支持!!

    如超出限制的并发数在客户端就会出现503错误 

    ----------------------------------------------------------------------------------------------

    限制IP连接数

    到这里下载模块 http://dominia.org/djao/limit/mod_limitipconn-0.04.tar.gz

    安装:
    tar zxvf mod_limitipconn-0.04.tar.gz
    cd mod_limitipconn-0.04
    make APXS=/usr/local/apache/bin/apxs 
    ß-----这里要按你自己的路径设置
    make install APXS=/usr/local/apache/bin/apxs
    ß-----这里要按你自己的路径设置

    编辑httpd.conf
    添加
    全局变量:
      < IfModule mod_limitipconn.c >
      
        < Location / >   # 所有虚拟主机的/目录
            
      MaxConnPerIP 3     # IP只允许3个并发连接
              NoIPLimit image/*  # 对图片不做IP限制
        < /Location >

      < Location /mp3 >  # 所有主机的/mp3目录
        MaxConnPerIP 1         # IP只允许一个连接请求    
        OnlyIPLimit audio/mpeg video    # 该限制只对视频和音频格式的文件
        < /Location >
    < /IfModule >

      

    或者虚拟主机的:
    < VirtualHost xx.xxx.xx.xx > ##ip
    地址
        ServerAdmin easy@phpv.net
        DocumentRoot /home/easy
        ServerName www.phpv.net
      < IfModule mod_limitipconn.c >
          < Location / >    
          MaxConnPerIP 5        
            
      NoIPLimit image/*      
          < /Location >
        
      < Location /mp3 >    # 所有主机的/mp3目录
          MaxConnPerIP 2         # IP只允许一个连接请求    
          OnlyIPLimit audio/mpeg video # 该限制只对视频和音频格式的文件
        
      < /Location >
      < /IfModule >
      < /VirtualHost >

     

    ----------------------------------------------------------------------------------------------

    限制带宽:

    下载模块 ftp://ftp.cohprog.com/pub/apache/module/1.3.0/mod_bandwidth.c
    安装:
    /usr/local/apache/bin/apxs -c ./mod_bandwidth.c -o /usr/local/apache/libexec/mod_bandwidth.so  

     

    <-------以上/usr/local/apache请设置为你的路径

    编辑httpd.conf
    添加:
     LoadModule bandwidth_module libexec/mod_bandwidth.so
    AddModule mod_bandwidth.c

    重启你的apache

    相关文档:

    Global configuration directives :

    • BandWidthDataDir
      Syntax : BandWidthDataDir <directory>
      Default : "/tmp/apachebw"
      Context : server config

    Sets the name of the root directory used by mod_bandwidth to store its internal temporary information. Don't forget to create the needed directories : <directory>/master and <directory>/link

    • BandWidthModule
      Syntax : BandWidthModule <On|Off>
      Default : Off
      Context : per server config

    Enable or disable totaly the whole module. By default, the module is disable so it is safe to compile it in the server anyway.

    PLEASE, NOTE THAT IF YOU SET A BANDWIDTH LIMIT INSIDE A VIRTUALHOST BLOCK, YOU ALSO __NEED__ TO PUT THE "BandWidthModule On" DIRECTIVE INSIDE THAT VIRTUALHOST BLOCK !

    IF YOU SET BANDWIDTH LIMITS INSIDE DIRECTORY BLOCKS (OUTSIDE OF ANY VIRTUALHOST BLOCK), YOU ONLY NEED TO PUT THE "BandWidthModule On" DIRECTIVE ONCE, OUTSIDE OF ANY VIRTUALHOST OR DIRECTORY BLOCK.

    • BandWidthPulse
      Syntax : BandWidthPulse <microseconds>
      Default :
      Context : per server config

    Change the algorithm used to calculate bandwidth and transmit data. In normal mode (old mode), the module try to transmit data in packets of 1KB. That mean that if the bandwidth available is of 512B, the module will transmit 1KB, wait 2 seconds, transmit another 1KB and so one.

    Seting a value with "BandWidthPulse", will change the algorithm so that the server will always wait the same amount of time between sending packets but the size of the packets will change. The value is in microseconds. For example, if you set "BandWidthPulse 1000000" (1 sec) and the bandwidth available is of 512B, the sever will transmit 512B, wait 1 second, transmit 512B and so on.

    The advantage is a smother flow of data. The disadvantage is a bigger overhead of data transmited for packet header. Setting too small a value (bellow 1/5 of a sec) is not realy useful and will put more load on the system and generate more traffic for packet header.

    Note also that the operating system may do some buffering on it's own and so defeat the purpose of setting small values.

    This may be very useful on especialy crowded network connection : In normal mode, several seconds may happen between the sending of a full packet. This may lead to timeout or people may believe that the connection is hanging. Seting a value of 1000000 (1 sec) would guarantee that some data are sent every seconds...

    Directory / VirtualServer configuration directives

    • BandWidth
      Syntax : BandWidth <domain|ip|all> <rate>
      Default : none
      Context : per directory, .htaccess

    Limit the bandwidth for files in this directory and sub-directories based on the remote host <domain> or <ip> address or for <all> remote hosts.

    Ip addresses may now be specified in the network/mask format. (Ie: 192.168.0.0/21 )

    The <rate> is in Bytes/second. A <rate> of "0" means no bandwidth limit.

    Several BandWidth limits can be set for the same directory to set different limits for different hosts. In this case, the order of the "BandWidth" keywords is important as the module will take the first entry which matches the client address.

    Example :
    <Directory /home/www>
    BandWidth ecp.fr 0
    BandWidth 138.195 0
    BandWidth all 1024
    </Directory>

    This will limit the bandwith for directory /home/www and all it's subdirectories to 1024Bytes/sec, except for .ecp.fr or 138.195..where no limit is set.

    • LargeFileLimit
      Syntax : LargeFileLimit <filesize> <rate>
      Default : none
      Context : per directory, .htaccess

    Set a maximal <rate> (in bytes/sec) to use when transfering a file of <filesize> KBytes or more.

    Several "LargeFileLimit" can be set for various files sizes to create range. The rate used for a given file size will be the one of the matching range.

    A <rate> of "0" mean that there isn't any limit based on the size.

    A <rate> of "-1" mean that there isn't any limit for that type of file. It's override even a BandWidth limit. I found this usefull to give priority to very small files (html pages, very small pictures) while seting limits for larger files... (users with their video files can go to hell ! :)

    Example :
    If the following limits are set :
    LargeFileLimit 200 3072
    LargeFileLimit 1024 2048

    That's mean that a file of less than 200KBytes won't be limited based on his size. A file with a size between 200KBytes (included) and 1023Kbytes (included) will be limited to 3072Bytes/sec and a file of 1024Kbytes or more will be limited to 2048Bytes/sec.

    • MaxConnection
      Syntax : MaxConnection <connections>
      Default : 0 (illimited)
      Context : per directory, .htaccess

    Restrict the number of maximum simultanous connections. If the limit is reached, new connections will be rejected. A value of 0 mean that there isn't any limits.

    • MinBandWidth
      Syntax : MinBandWidth <domain|ip|all> <rate>
      Default : all 256
      Context : per directory, .htaccess

    Set a minimal bandwidth to use for transfering data. This over-ride both BandWidth and LargeFileLimit rules as well as the calculated rate based on the number of connections.

    The first argument is used in the same way as the first argument of BandWidth.

    <rate> is in bytes per second.

    A rate of "0" explicitly means to use the default minimal value (256 Bytes/sec).

    A rate of "-1" means that the minimal rate is equal to the actual rate defined by BandWidth and LargeFileLimit. In fact, that means that the final rate won't depend of the number of connections but only on what was defined.

    Example :
    If BandWidth is set to "3072" (3KBytes/sec) and MinBandWidth is set to "1024" (1KBytes/sec) that means :
    - if there is one connection, the file will be transfered at 3072 Bytes/sec.
    - if there is two connections, each files will be transfered at 1536 Bytes/sec.
    - if there is three or more connections, each files will be transfered at 1024 Bytes/sec. (Minimal of 1024 Bytes/sec).

    If MinBandWidth is set to "-1" that means :
    - if there is one connection, the file will be transfered at 3072 Bytes/sec.
    - if there is two or more connections, each files will be transfered at 3072 Bytes/sec. In effect, the rate doesn't depend anymore on the number of connections but only on the configuration values.

    Note that the total transfer rate will never exceed your physical bandwidth limitation.

    Note : If both a "BandWidth" and a "LargeFileLimit" limit apply, the lowest one will be used. (But never lower than the "MinBandWidth" rate)

    If both a virtual server limit is defined and another apply for a directory under this virtual server, the directory limit will over-ride it.

    If a limit is defined outside a Directory or VirtualHost directive, it will act as default on a per virtual server basis. (Ie: each virtual server will have that limit, _independantly_ of the other servers)

    FAQ:

    <!--StartFragment -->

    1.      I installed the module but the bandwidth isn't limited

    2.      It worked fine the first time but now the server is very slow

    3.      My PHP pages are displayed in plain text

    4.      My CGI are not working anymore

    5.      I can't submit any data using a HTML form anymore

     

    1.      I installed the module but the bandwidth isn't limited

    You should make sure that the "master" and "link" directories exist and are read,write,execute for the user under which the server run.

    By default, mod_bandwidth use :
    /tmp/apachebw/master
    /tmp/apachebw/link

    If you set a limit inside a "Directory" block, you should make sure that the path is really the one used to serve documents.

    2.      It worked fine the first time but now the server is very slow

    Make sure that there isn't and "dead" links in the mod_bandwidth "link" directory when you start the server. It's better to run the "cleanlink.pl" utility we provide.

    3.      My PHP pages are displayed in plain text

    If your PHP pages are displayed correctly when the module isn't activated but are sent in plain text when you try to use mod_bandwidth, that's probably because mod_bandwidth is called before the PHP module.

    Please, read the documentation to see how to give the lowest priority to mod_bandwidth so that it will be executed last.

    4.      My CGI are not working anymore

    See the previous question...

    5.      I can't submit any data using a HTML form anymore

    See the previous question...

    发表于 @ 2004年10月29日 20:38:00|评论(loading...)|编辑

    新一篇: Apache 实现禁止图片盗链 | 旧一篇: 程序员的“素质”是什么?

    评论

    #珠宝 发表于2006-06-08 16:49:00  IP: 61.157.91.*
    [url=http://www.honey-moon.com.cn/jianjie.htm]珠宝[url]
    [url=http://www.honey-moon.com.cn/shop/index.asp]珠宝[url]
    [url=http://www.tyfohq.com]周易[url]
    [url=http://www.tyfohq.com/zhouyi.htm]周易[url]
    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © 六道