It’s been more than 2 months now that I’ve been using Nginx (read: Engine X) as a reverse proxy server with Apache to serve static files such as JavaScript, CSS, images, etc. You can refer to my previous post about how to install nginx as a reverse proxy on your web server. The result is that my website loading time is much faster.
Well, at first installation I used nginx v0.7.63 and the latest stable version as I write this post is v0.8.53. There are a lot of changes and bug fixes. So I decided to upgrade it to the latest one.
Nginx can be upgraded without downtime. To do that, please follow the steps below:
1. First, log in 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 a backup of 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 sends a USR2 signal to the current pid file. As a result, the nginx master process will rename its pid and start the new binary.
6. Check the process:
ps aux | grep nginx
In this case my old nginx process ID is 15651.
7. To shut down 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 expected. If there are no problems or errors, kill the old nginx process:
kill -QUIT 15651
9. Now your nginx has been upgraded.
The result of this change isn’t that noticeable, but staying secure and up to date with the latest technology is one way to secure your server and keep learning. I have a hungry mind to feed, so I did this. Hope you like it.
