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