下面按排查思路给你一个 Linux 下排查 Nginx 故障的实用清单,从“最快定位”到“深入分析”。
ps -ef | grep nginx
或
systemctl status nginx
✅ 正常应看到 master process 和 worker process
❌ 没运行:systemctl start nginx
ss -lntp | grep ':80\|:443'
或
netstat -lntp | grep nginx
常见问题:
tail -f /var/log/nginx/error.log
常见错误:
permission denied → 权限问题address already in use → 端口冲突no such file or directory → 路径错误SSL_CTX → 证书问题tail -f /var/log/nginx/access.log
看:
例如:
GET /api HTTP/1.1" 502
nginx -t
若有错误,会直接告诉你行号。
重新加载配置:
nginx -s reload
通常是:
检查:
proxy_pass http://127.0.0.1:8080;
测试后端:
curl http://127.0.0.1:8080
proxy_read_timeout 太小ls -l /var/www/html
Nginx 用户一般是:
www-data(Debian/Ubuntu)nginx(CentOS)修复权限示例:
chown -R www-data:www-data /var/www/html
iptables -L
# 或
ufw status
getenforce
临时关闭测试:
setenforce 0
curl -I http://localhost
看返回头:
200 OK301/302 跳转403 Forbidden| 现象 | 可能原因 |
|---|---|
| 403 | 目录无权限 / index 文件缺失 |
| 404 | root 路径错误 |
| 502 | 后端挂了 |
| 504 | 后端超时 |
| 空白页 | PHP / 后端报错 |
| 无法访问 | 防火墙 / 端口未监听 |
如果你愿意,可以把:
发出来,我可以帮你精确分析。