How to automatically restart Nginx
Here is instruction how to launch Nginx server after close unexpectedly.
1. Create /root/nginxfix.sh file with next content:
#!/bin/bash PATH=/usr/sbin:/usr/bin:/sbin:/bin if [[ ! "$(/etc/init.d/nginx status)" =~ "active (running)" ]] then echo $(date -u) "NGINX server has been stopped. It has now been restarted." service nginx start fi
2. Make it executable chmod +x /root/nginxfix.sh
3. sudo crontab -e
4. Add crontab job. For 3 min period job will be next:
*/3 * * * * /root/nginxfix.sh >> /var/log/nginxfix.log 2>&1
/var/log/nginxfix.log – log file
Let me know better approach in comments.