Nginx 服务运行一段时间后挂掉可能由多种原因导致,以下是最常见的原因及对应的解决方案:
error.log
和系统日志(/var/log/messages
或 journalctl
)worker_rlimit_nofile
值worker_processes
和 worker_connections
配置pmap
或 valgrind
检查内存泄漏proxy_connect_timeout
, proxy_read_timeout
keepalive
保持上游连接nginx
worker_rlimit_nofile 65535;
/etc/security/limits.conf
nginx -t
测试配置debug_connection
调试特定IPtop
, htop
监控资源检查日志:
tail -n 100 /var/log/nginx/error.log
journalctl -u nginx --no-pager -n 100
检查核心转储:
grep -i core /var/log/messages
ulimit -c unlimited # 启用核心转储
监控Nginx状态:
nginx -V # 查看编译参数和版本
nginx -t # 测试配置
使用调试工具:
strace -p <nginx-worker-pid>
gdb -p <nginx-worker-pid>
ini
[Service]
Restart=always
RestartSec=5s
如果问题仍然存在,建议提供具体的错误日志以便更精确地诊断问题。