Debian 上 Nginx “慢”通常不是 Nginx 本身的问题,而是系统配置、资源、网络或应用层导致的。下面按最常见原因 → 排查方法 → 解决建议说明。
Nginx 在以下情况会做 DNS 解析:
proxy_pass http://域名fastcgi_pass 用到域名resolver 配置不当表现
解决
proxy_pass http://127.0.0.1:8080;
用 IP 代替域名
或配置:
resolver 127.0.0.1 valid=10s;
很多人说“Nginx 慢”,其实是:
验证
time curl http://localhost/
time curl http://localhost/index.php
如果静态页快、PHP 慢 → 问题在后端
Debian 的 Nginx 默认:
worker_processes 可能 = 1worker_connections 小sendfile / tcp_nopush优化示例
worker_processes auto;
events {
worker_connections 10240;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
}
常见于:
检查
iostat -x 1
或
dmesg | grep error
解决
access_log off;
Debian 默认启用 IPv6,某些网络下:
localhost 解析到 ::1表现
curl localhost 慢curl 127.0.0.1 快解决
listen 80;
# 而不是
listen [::]:80
ufw 规则复杂fail2ban 扫描检查
systemctl status fail2ban
优化
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_protocols TLSv1.2 TLSv1.3;
# 1. 静态页快慢
curl -w "%{time_total}\n" http://127.0.0.1/
# 2. PHP 快慢
curl -w "%{time_total}\n" http://127.0.0.1/index.php
# 3. DNS
getent hosts yourdomain
# 4. 系统资源
top
df -h
iostat -x 1
你可以告诉我:
cat /etc/debian_version)我可以直接给你针对性配置。