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