Nginx stops working suddenly and I can't find the reason
Need more information
It's hard to say exactly what the problem is without more information. Just gonna throw some thoughts your way. Edit your post with more information and maybe we can figure it out.
Questions
- How is nginx being run? Is it being run using a service or using an ad-hoc method?
- If it's being run by init (upstart, systemd, etc), they (usually?) will log something about the process being restarted. If not, you could look at the init job and add a log print for when it is started / stopped.
- Is there anything relevant in
/var/log/syslog
? - Save the
stdout
/stderr
from nginx. Something like this. Maybe you'll catch something interesting when it happens again.nohup /usr/local/nginx/sbin/nginx >> /var/log/nginx.out 2>&1 &
-
Run a script that will log whenever it sees nginx die. You could then use this to correlate it with other events on the system.
while true; do NUM_INSTANCES=$(ps -A | grep nginx | wc -l) if [[ "$NUM_INSTANCES" == 0 ]]; then echo "$(date) nginx just died" >> /var/log/syslog fi sleep 1 done
You could also replace the
echo
with a logger call. I've used a similar script to debug my systems. Just be sure to run this in a script file instead of a shell, so you can kill it by doingkillall <scriptname>.sh
.
Also, some of the info on the nginx debugging page may be helpful. https://www.nginx.com/resources/wiki/start/topics/tutorials/debugging/