Call us Toll-Free:
1-800-218-1525
Live ChatEmail us

 Sponsors

Recompile/upgrade nginx binary with no down-time

Kyle Deneen, 05-31-2008
How to recompile nginx and replace current binary, with no down-time:

Follow the same generic steps as a regular install initially.

1. Download and untar the nginx source if you don't have it on your machine already.

2. Make a copy of your current nginx binary and conf. The installation usually does this automatically, but just to be safe.

"cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_old"
"cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.old"

3. Run the "./configure" command. For example if you wanted to add SSL support to nginx, you would have a configure statement such as:

./configure --with-http_ssl_module --with-openssl=/path/to/openssl_src

If you have other options you need you can add those as well. To see what your current nginx has configured, run the binary with -V flag ie.

"/usr/local/nginx/sbin/nginx -V"

4. run: "make install clean" This will install the new binary in place of the old one and makes a backup of the old one.

These steps are more specific to replacing a current install without down-time:

5. Send a USR2 signal to the current pid file, something like:

"kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`".

This causes nginx master process that was running to rename its pid and start the new binary. Both will run simultaneously.

6. To disable the old workers, send the old master process a WINCH signal. If your pid is '123' that would be something like:

"kill -WINCH 123"

7. Now you can test the new nginx process to see if it's working. If it is, you can kill the old master process to allow the new one to take over. If the old master process had a PID of '123' you would do this:

"kill -QUIT 123"

If you find your new binary isn't working correctly, maybe due to a mistake during configuration, you can revert back to the old master process by doing the following. Assume your old master process has a PID of '123' and the new master process has a PID of '321':

"kill -HUP 123" - this will restart the workers under the old master process
"kill -QUIT 321" - shuts down the new master process workers
"kill -TERM 321" - shuts down the new master process

You can find some additional information about nginx upgrades and signals here:

http://wiki.codemongers.com/NginxCommandLine#utnbotf

Social, 09-22-2012
hi,

will this tutorial still work for the current nginx version and all other current versions of wordpress, php-fpm, mysql, etc??? thanks
Enjoyed this post?

Subscribe Now to receive new posts via Email as soon as they come out.

 Comments
Post your comments












Note: No link spamming! If your message contains link/s, it will NOT be published on the site before manually approved by one of our moderators.



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions