nginx限制下載速度

1.搭建一個ngx服務器,放置配置文件包,提供給2000+臺VPS讀取下載,考慮到帶寬佔用的問題,決定在nginx上作下載限速處理。html

環境:centos7+nginx1.12nginx

根據官方文檔以下:centos

2.對nginx.conf進行配置:服務器

http {
  ...
  limit_conn_zone $binary_remote_addr zone=addr:10m;   # 添加該行
  ...
  include vhost/*.conf;
}

3.配置server模塊centos7

server {
    listen *:8080;
    server_name localhost;
    location / {
        root /usr/local/test;
        index index.html;
        limit_conn addr 1; # 每一個客戶端只容許一個線程。
        limit_rate 100k;  # 每一個線程最大下載速度100k
        }

    }

每一個客戶端最終的下載速度 = limit_conn * limit_rate   我這裏很明顯是100kb/sspa

 參考和轉載自:https://www.cnblogs.com/hukey/p/6072904.html線程