nginx 日志频繁报错的原因有很多,需要先看具体报错内容才能准确判断。下面我按「常见报错类型 → 可能原因 → 排查/解决办法」给你一个系统性的梳理,你可以对照自己的日志。
502 Bad Gateway日志常见:
connect() failed (111: Connection refused) while connecting to upstream
可能原因:
排查:
ps aux | grep php-fpm
netstat -lntp | grep 9000
curl http://127.0.0.1:端口
504 Gateway Time-out日志常见:
upstream timed out (110: Connection timed out)
原因:
proxy_read_timeout解决:
proxy_read_timeout 60s;
proxy_connect_timeout 10s;
403 Forbidden日志常见:
directory index of "/path/" is forbidden
原因:
index 文件autoindex off检查:
ls -l /var/www/html
ps aux | grep nginx
404 Not Found原因:
注意:
root 和 alias 混用是高频坑Too many open files日志常见:
worker_connections are not enough
原因:
解决:
ulimit -n 65535
worker_rlimit_nofile 65535;
SSL_do_handshake() failed
tail -f /var/log/nginx/error.log
awk '{print $9}' access.log | sort | uniq -c | sort -rn
nginx -t
你可以把具体的错误日志内容(哪怕几行)发出来,例如:
我可以直接告诉你是哪一行的配置问题,以及怎么改。