Nginx 日志中出现报错的原因有很多种,下面我按常见类型 + 典型报错示例 + 可能原因给你系统梳理一下,方便你对照排查。
日志示例
nginx: [emerg] unknown directive "server_" in /etc/nginx/nginx.conf:12
原因
{} 层级;排查
nginx -t
日志示例
bind() to 0.0.0.0:80 failed (98: Address already in use)
原因
解决
lsof -i:80
kill -9 <pid>
日志示例
Permission denied) while reading upstream
或
open() "/var/www/html/index.html" failed (13: Permission denied)
原因
解决
chown -R nginx:nginx /var/www
chmod 755 /var/www
日志示例
connect() failed (111: Connection refused) while connecting to upstream
原因
排查
curl http://127.0.0.1:8080
日志示例
upstream timed out (110: Connection timed out)
原因
优化
proxy_read_timeout 60s;
proxy_connect_timeout 10s;
日志示例
SSL_CTX_use_certificate_chain_file("...") failed
原因
检查
openssl x509 -noout -text -in cert.pem
日志示例
404 Not Found
或
open() "/usr/share/nginx/html/test.html" failed (2: No such file or directory)
原因
日志示例
413 Request Entity Too Large
解决
client_max_body_size 20m;
✅ 第一步:看错误类型
tail -n 50 /var/log/nginx/error.log
✅ 第二步:区分
emerg → 启动失败error → 运行异常warn → 一般不影响✅ 第三步:结合 access.log
tail -n 20 /var/log/nginx/access.log
你可以直接贴出:
我可以帮你逐行分析并给出修改方案。