在 Debian 上 Nginx 访问慢 的原因很多,下面按最常见 → 较少见的顺序给你排查思路,基本照着做就能定位问题。
先确认慢在哪一环节:
curl -w "@curl-format.txt" -o /dev/null -s http://你的站点
curl-format.txt:
time_namelookup: %{time_namelookup}\n
time_connect: %{time_connect}\n
time_starttransfer:%{time_starttransfer}\n
time_total: %{time_total}\n
time_connect 大 → 网络 / 防火墙问题time_starttransfer 大 → 后端 / PHP / 数据库慢time_total 大但前面都小 → 传输慢(带宽)如果你是:
检查:
ps aux | grep php
或查看:
/var/log/php*-fpm.log
✅ 解决:
pm.max_childrenNginx 默认会尝试 反向 DNS 解析客户端 IP
在 nginx.conf 或 server 块中加:
resolver_timeout 5s;
或修改:
server {
# 关闭 host 反查
# 一般不需要
}
✅ 更直接:
vim /etc/nginx/nginx.conf
确保:
worker_rlimit_nofile 65535;
events {
worker_connections 10240;
}
Debian 11+ 用 nftables
检查:
nft list ruleset
iptables -L -n
✅ 临时测试:
systemctl stop nftables
高并发时写日志很慢
access_log off;
或:
access_log /var/log/nginx/access.log buffer=32k flush=1s;
nproc
nginx.conf:
worker_processes auto;
gzip on;
gzip_types text/css application/javascript;
iostat -x 1
或:
dmesg | tail
free -h
swapon --show
date
timedatectl
如果是 HTTPS 访问慢,HTTP 正常:
ssl_stapling off;
# 1. 看 nginx 错误
tail -f /var/log/nginx/error.log
# 2. 看系统负载
top
# 3. 看网络
ping 你的IP
mtr 你的IP
# 4. 看后端
systemctl status php8.2-fpm
你可以贴:
我可以直接告诉你最可能的那一个原因 + 改哪一行配置。