---

title: Nginx 请求限流 limit_req 与热路径保护策略

keywords: limit_req, limit_req_zone, burst, nodelay, 429, 热路径

description: 使用 Nginx 限流模块为高并发热路径设置速率与突发保护,避免雪崩与过载。

categories:

  • 文章资讯
  • 技术教程

---

定义限流共享区与状态码:

limit_req_status 429;
limit_req_zone $binary_remote_addr zone=ip_req_zone:10m rate=20r/s;

对关键接口实施限流与突发控制:

server {
  listen 80;
  server_name api.example.com;

  location /api/checkout {
    limit_req zone=ip_req_zone burst=40 nodelay;
    proxy_pass http://backend_checkout;
  }

  location /api/search {
    limit_req zone=ip_req_zone burst=80;
    proxy_pass http://backend_search;
  }
}

并发连接限制(可选):

limit_conn_zone $binary_remote_addr zone=ip_conn_zone:10m;
server {
  location / {
    limit_conn ip_conn_zone 50;
  }
}

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部