I recently came across a problem with a nginx server where it goes down randomly after some period of time. Whether this is related to Segfault bug or just OOM Killer doing its duty, you can configure nginx to auto-restart after a failure as a temporary workaround. You can avoid hours of downtime and having to manually start nginx using this method.
First you need to make sure there are no configuration errors in your nginx. Following command will help with that.
nginx -t
If the configuration is fine, you can configure systemd to auto-restart nginx on failure. Create a new directory inside systemd.
mkdir /etc/systemd/system/nginx.service.d/
Create override.conf inside the new directory.
nano /etc/systemd/system/nginx.service.d/override.conf
Paste following content,
[Unit] StartLimitIntervalSec=500 StartLimitBurst=5 [Service] Restart=on-failure RestartSec=5s
Reload daemon service,
systemctl daemon-reload
And then restart nginx,
systemctl restart nginx.service
This will restart nginx 5 seconds after the failure.
You can control how long systemd should wait to restart nginx by adjusting RestartSec value.
This gives you time to find and troubleshoot the actual error without worrying about the downtime.