在CentOS上使用Nginx限制帶寬,可通過以下方法實現:
limit_rate
指令,在http
或server
塊中設置,如limit_rate 100k;
,可限制所有請求的響應速度為100KB/s。location
塊中使用limit_rate
,如location /download/ { limit_rate 500k; }
,僅對/download/
路徑下的請求限速500KB/s。limit_rate_after
和limit_rate
,如location ~ \.mp4$ { limit_rate_after 1m; limit_rate 500k; }
,表示大文件下載時,前1MB不限速,之后限速500KB/s。