Setup Supervisord to keep nginx alive
Photo by Carlos Muza
Setup Supervisord to keep nginx alive
In some cases in the production environment, we faced downtime of the website, Nginx process disappeared. We want to keep the Nginx always alive without any reasons. So, we use the Supervisord as a supervisor who make sure Nginx is always alive
Add Nginx configuration on Supervisord
1$ sudo vim /etc/supervisor/conf.d/nginx.conf23[program:nginx]4command=/usr/sbin/nginx -g "daemon off;"5autostart=true6autorestart=true7startretries=58numprocs=19startsecs=010process_name=%(program_name)s_%(process_num)02d11stderr_logfile=/var/log/supervisor/%(program_name)s_stderr.log12stderr_logfile_maxbytes=10MB13stdout_logfile=/var/log/supervisor/%(program_name)s_stdout.log14stdout_logfile_maxbytes=10MB
Let supervisord know about new config.
1$ sudo supervisorctl reread2nginx: available
Let supervisord start nginx service
1$ sudo supervisorctl update2nginx: added process group
Verify if supervisor started nginx service.
1sudo supervisorctl2nginx:nginx_003supervisor>
Then done, you can try to stop the nginx service and you see the new Nginx's proccess always start the new one.