Upgrade Nginx Without Downtime

It’s been more than 2 months now i have been using Nginx (read: Engine X) as reverse proxy server with Apache to server static files such as javascripts, css, images, etc. You can refer to my previous post about how to install nginx as reverse proxy in your web server. The result is, my website loading time is much faster.

Well at first installation i used nginx v0.7.63 and the latest stable as i write this post is v0.8.53. There are lot of changes and bug fixes. So i decided to upgrade it to the latest one.

Nginx can be upgrade without downtime, to do that please follow the steps below:

  1. First login as root to your server via SSH.
  2. Download the latest nginx package:
    cd /usr/src  #working directory
    wget http://nginx.org/download/nginx-0.8.53.tar.gz
  3. Make backup if your old nginx binary (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
  4. Install the new nginx:
    cd /usr/src
    tar xvzf nginx-0.8.53.tar.gz
    cd nginx-0.8.53
    ./configure --with-http_ssl_module --with-http_realip_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module
    make
    make install
  5. Run the new nginx binary simultaneously with the old one without killing the old one yet:
    kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`

    note: this command will send a USR2 signal to the current pid file, as the result is nginx master process will rename its pid and start the new binary.

  6. Check the process is:
    ps aux | grep nginx

    in this case my old nginx process id is 15651.

  7. So i want to shutdown the old process, don’t instantly kill it with ‘-9′, instead use WINCH:
    kill -WINCH 15651
  8. Now test your website, and see if it is working as it is. If no problem or error, now kill the old nginx process:
    kill -QUIT 15651
  9. Now your nginx has been upgraded.

As the result of this change is not that much i can feel. But just to be secured and have an latest update technology is one way to secure your server and learning a new thing. I have a hungry mind to feed, so i did this. Hope you like it.

Comments

  1. rbaltas says:

    After upgrade nginx version still showing up as 1.0.12 when I type:
     
    nginx -v
     

Give me your feedback

This site uses Akismet to reduce spam. Learn how your comment data is processed.