Nginx 1.18服务器压测遇429错误,关闭limit_rate仍未解决
Nginx禁用速率限制后仍出现429 Too Many Requests错误
问题详情
服务器配置:2vCPU、7GB内存,运行Nginx 1.18版本
负载测试场景:每秒约300次HTTP请求
现象:测试开始几秒后返回429错误,已通过limit_rate 0禁用Nginx速率限制,问题未解决。
当前Nginx Server配置
server { listen 80; listen [::]:80; server_name _; root /var/www/laravel-rsync/public; add_header X-Frame-Options "SAMEORIGIN"; add_header X-Content-Type-Options "nosniff"; index index.php; charset utf-8; limit_rate 0; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; location ~ \.php$ { fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.(?!well-known).* { deny all; } }
解决方法
问题出在应用层而非Nginx:Laravel默认对所有/api路由启用了节流(throttle)中间件,这是触发429错误的真正原因。
只需修改Laravel的路由配置即可解决:
- 打开路由文件
routes/api.php - 找到包含
throttle中间件的路由组配置,注释掉该中间件即可。
内容的提问来源于stack exchange,提问作者user17179924
相关产品推荐
相关产品推荐

