This site runs best with JavaScript enabled.

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.conf
2
3[program:nginx]
4command=/usr/sbin/nginx -g "daemon off;"
5autostart=true
6autorestart=true
7startretries=5
8numprocs=1
9startsecs=0
10process_name=%(program_name)s_%(process_num)02d
11stderr_logfile=/var/log/supervisor/%(program_name)s_stderr.log
12stderr_logfile_maxbytes=10MB
13stdout_logfile=/var/log/supervisor/%(program_name)s_stdout.log
14stdout_logfile_maxbytes=10MB

Let supervisord know about new config.

1$ sudo supervisorctl reread
2nginx: available

Let supervisord start nginx service

1$ sudo supervisorctl update
2nginx: added process group

Verify if supervisor started nginx service.

1sudo supervisorctl
2nginx:nginx_00
3supervisor>

Then done, you can try to stop the nginx service and you see the new Nginx's proccess always start the new one.

Discuss on TwitterEdit post on GitHub

Share article
Kent C. Dodds

Kent C. Dodds is a JavaScript software engineer and teacher. He's taught hundreds of thousands of people how to make the world a better place with quality software development tools and practices. He lives with his wife and four kids in Utah.