Daniel's Blog

Reloading Nginx's Config files without restarting

TLDR

killall -SIGHUP nginx

Reloading Nginx

A common problem to encounter with nginx is to reload the nginx config without any downtime.

With most of our servers it is simple to do this:

$ sudo /etc/init.d/nginx configtest
 * Testing nginx configuration                                   [ OK ]
$ sudo /etc/init.d/nginx reload
[ ok ] Reloading nginx configuration (via systemctl): nginx.service.

However, I ran into a docker image that loads the service using the s6 service monitor which I was unfamiliar with. I have used supervisord and it seemed similar to that.

It was running the nginx service and the usual /etc/init.d wasn't there.

Instead there was /etc/cont-init.d which had these files in it:

/etc/cont-init.d $ ls -1 .
00-startup
01-timezone
02-permissions
03-monitoring
04-scheduling
05-logging
06-messaging
07-firewall
10-nginx
11-nginx-config-reload
20-php-fpm
30-freescout
99-container

I tried executing the 11-nginx-config-reload script but that didn't seem to work.

So I used an old standby, sending the SIGHUP signal.

In the nginx docs, it reads that reloading the config is sending that signal.

Looking at the processes in the machine:

 $ ps auxf | grep nginx
 2187 root      0:00 s6-supervise 10-nginx
 2328 root      0:00 nginx: master process nginx
 2336 nginx     0:00 nginx: worker process
 2338 nginx     0:00 nginx: worker process
 2339 nginx     0:00 nginx: worker process
 2340 nginx     0:00 nginx: worker process
 2341 nginx     0:00 nginx: worker process
 2343 nginx     0:00 nginx: worker process
 2344 nginx     0:00 nginx: worker process
 2345 nginx     0:00 nginx: worker process
 2346 nginx     0:00 nginx: worker process
 2347 nginx     0:00 nginx: worker process
 2348 nginx     0:00 nginx: worker process
 2349 nginx     0:00 nginx: worker process
 2351 nginx     0:00 nginx: worker process
 2352 nginx     0:00 nginx: worker process
 2353 nginx     0:00 nginx: worker process
 2354 nginx     0:00 nginx: worker process
 2355 nginx     0:00 nginx: worker process
 2356 nginx     0:00 nginx: worker process
 2357 nginx     0:00 nginx: worker process
 2360 nginx     0:00 nginx: worker process
 2361 nginx     0:00 nginx: worker process
 2364 nginx     0:00 nginx: worker process
 2367 nginx     0:00 nginx: worker process
 2370 nginx     0:00 nginx: worker process
 2371 nginx     0:00 nginx: worker process
 2373 nginx     0:00 nginx: worker process
 2374 nginx     0:00 nginx: worker process
 2376 nginx     0:00 nginx: worker process
 2377 nginx     0:00 nginx: worker process
 2378 nginx     0:00 nginx: worker process
 2379 nginx     0:00 nginx: worker process
 2382 nginx     0:00 nginx: worker process

There were lots of them. So I utilized the killall command.

$ killall -SIGHUP nginx

It reloaded the config file and I was able to continue testing. Eventually I had a working config, applied the changes to the infrastructure-as-code repo and deployed it to the staging machines to test.