nginx限速,

來源:互聯網
上載者:User

nginx限速,

注意:

nginx 1.1.8 之後的版本的文法改為limit_conn_zone $binary_remote_addr zone=NAME:10m;

NAME 就是 zone 的名字詳情請看這裡 http://nginx.org/en/docs/http/ngx_http_limit_conn_module.html

 

限制串連數:

要限制串連,必須先有一個容器對串連進行計數,在http段加入如下代碼:

"zone=" 給它一個名字,可以隨便叫,這個名字要跟下面的 limit_conn 一致

$binary_remote_addr = 用二進位來儲存用戶端的地址,1m 可以儲存 32000 個並發會話

 

... 省掉 N 字

http

{

limit_conn_zone $binary_remote_addr zone=addr:10m;

 

接下來需要對server不同的位置(location段)進行限速,比如限制每個IP並發串連數為1,則

server

{

listen 80;

server_name 192.168.11.128;

index index.html index.htm index.php;

limit_conn addr 1; #是限制每個IP只能發起1個串連 (addr 要跟 limit_conn_zone 的變數對應)

limit_rate 100k; #限速為 100KB/秒

root html;

 

注意事項:

limit_rate 100k; //是對每個串連限速100k。這裡是對串連限速,而不是對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.