nginx 限速

來源:互聯網
上載者:User

nginx限制ip並發數,也是說限制同一個ip同時串連伺服器的數量

1.添加limit_zone
這個變數只能在http使用
vi /usr/local/nginx/conf/nginx.conf
limit_zone one $remote_addr 10m;

2.添加limit_conn
這個變數可以在http, server, location使用
我只限制一個網站,所以添加到server裡面
vi /usr/local/nginx/conf/host/gaojinbo.com.conf
limit_conn   one 10;

3.重啟nginx 
killall -HUP nginx 

nginx 限速模組

參考:

  • 關於limit_zone:http://wiki.nginx.org/NginxHttpLimitZoneModule
  • 關於limit_rate和limit_conn:http://wiki.nginx.org/NginxHttpCoreModule

nginx可以通過HTTPLimitZoneModule和HTTPCoreModule兩個組件來對目錄進行限速。

http {
  limit_zone   one  $binary_remote_addr  10m; 
  server {
    location /download/ {
      limit_conn   one  1;
      limit_rate 300k;
    }
  }
}

limit_zone,是針對每個IP定義一個儲存session狀態的容器。這個樣本中定義了一個10m的容器,按照32bytes/session,可以處理320000個session。

limit_conn one 1;
限制每個IP只能發起一個並發串連。

limit_rate 300k;
對每個串連限速300k. 注意,這裡是對串連限速,而不是對IP限速。如果一個IP允許兩個並發串連,那麼這個IP就是限速limit_rate×2。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.