Nginx 连接数的管理与落地实践
一 核心概念与监控
server {
listen 443 ssl;
server_name localhost;
location /nginx-status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}
关键指标含义:
二 限制并发连接的核心配置
http {
limit_conn_zone $binary_remote_addr zone=addr:10m;
server {
listen 80;
server_name example.com;
location /download/ {
limit_conn addr 1;
limit_conn_log_level notice;
limit_conn_status 429;
}
}
}
http {
limit_conn_zone $binary_remote_addr zone=perip:10m;
limit_conn_zone $server_name zone=perserver:10m;
server {
listen 80;
server_name app.example.com;
limit_conn perip 10;
limit_conn perserver 200;
}
}
nginx -t && systemctl reload nginx。limiting connections by zone "addr"。三 日志观测与容量调优
limiting connections 提示与返回码 429/503,结合 access.log 的 $status、$request_time、$upstream_response_time 定位是连接瓶颈还是后端慢。四 进阶用法与注意事项