nginx限制下載速度


1、nginx.conf配置

http {
  ...
  limit_conn_zone $binary_remote_addr zone=addr:10m;
  ...
  include configs/nginx/nginx_http/*.conf;
}

2、配置nginx_http文件:

server {
  listen 80;

  server_name localhost;

  location / {
    root /app/video/www;
    index index.html index.htm;
    try_files $uri $uri/ /index.html;
    add_header Cache-Control no-cache;
    add_header Access-Control-Allow-Origin *;
    limit_conn addr 1; # 每個客戶端只允許一個線程
    limit_rate 1024k; # 每個線程最大下載速度1M
  }

  location /api/ {
    proxy_pass http://172.15.0.3:3000;
    proxy_redirect off;

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

3、本地直接使用wget進行測試: 最大速度1024kb/s

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM