pindleskin
V2EX  ›  问与答

nginx里limit_conn_zone和limit_req_zone内存参数应该怎样计算?

  •  
  •   pindleskin · Dec 15, 2013 · 8438 views
    This topic created in 4555 days ago, the information mentioned may be changed or developed.
    我看到nginx里有两个防止dos的配置:
    limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m;
    limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=5r/s;
    不知道上面这两个配置里storage的大小怎样计算?我看到说明里下面这么一句话:
    One megabyte zone can keep about 32 thousand 32-byte states or about 16 thousand 64-byte states. If the zone storage is exhausted, the server will return the 503 (Service Temporarily Unavailable) error to all further requests.
    按照这个意思,这个storage必须放入所有访问的ip?
    阻止ddos攻击还有别的简单的解决方案吗?
    8 replies    1970-01-01 08:00:00 +08:00
    freestyler
        1
    freestyler  
       Dec 15, 2013   ❤️ 1
    只有超过限制频率的ip才会存起来,不是所有访问ip。
    pindleskin
        2
    pindleskin  
    OP
       Dec 15, 2013
    @freestyler 多谢。也就是说一般情况下,10m可以存放16万个ip,应该够用了?根据说明,好像这个storage一旦用完,server就一直是503了,这个貌似相当可怕
    julyclyde
        3
    julyclyde  
       Dec 16, 2013
    @freestyler 那在它存起来之前怎么统计频率呢?
    qiongqi
        4
    qiongqi  
       Dec 16, 2013
    漏桶算法吧。
    你可以找nginx的源代码看一下。
    freestyler
        5
    freestyler  
       Dec 16, 2013
    @pindleskin 假设你设的限制是10r/s. 要用完10m, 需要160k个ip同时以这个频率访问你的站点.
    freestyler
        6
    freestyler  
       Dec 16, 2013
    @julyclyde 没说清楚,其实都有存的,只是没超过频率的ip状态是会被替换出去的.
    julyclyde
        7
    julyclyde  
       Dec 30, 2013
    @freestyler 既然替换出去,那就永远到不了指定的数了
    freestyler
        8
    freestyler  
       Jan 2, 2014
    @julyclyde 同时有超过频率访问的ip就会超了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3022 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 08:42 · PVG 16:42 · LAX 01:42 · JFK 04:42
    ♥ Do have faith in what you're doing.