Sunday 29 December 2013

Upgrading your custom compiled Nginx instance on Webfaction.

I’ve been running my own compiled instance of Nginx on Webfaction for some time now and I was overdue an upgrade. In this post I’ll run through all of the steps that I performed to upgrade my old installation of 1.1.15 to a more the most recent version ( 1.4.4 at the time of writing ). Ideally I wanted to do this without downtime.

Backup old config

Just in case things go South, I’d urge you to back up your current config as you may very well overwrite some files in this process. It is MUCH better to have spare copies than have no copies.

If you’ve followed my older guide then this config will likely be in /home/YOU/local/etc/nginx.conf. Let’s back it up and use this as a change to do some basic brace expansion

cp ~/local/etc/nginx.conf{,.backup}

Warned. You has been.

Download, unzip

This is the easy bit –

cd ~/src/
tar -zxvf nginx-1.4.4.tar.gz
cd nginx-1.4.4

Configure, make & make install.

This is mostly the same as my original compile flags but I’ve added some more modules into the mix. If you’ve forgot what options your previous Nginx install was compiled with then you can do this –

nginx -V

Here’s what I compiled my new version with –

./configure   --prefix=$HOME/local/nginx  \
--sbin-path=$HOME/local/sbin/nginx \
--conf-path=$HOME/local/etc/nginx.conf  \
--error-log-path=$HOME/logs/user/nginx/error.log \
--http-log-path=$HOME/logs/user/nginx/access.log \
--pid-path=$HOME/local/run/nginx/ \
--lock-path=$HOME/local/lock/nginx.lock \
--http-client-body-temp-path=$HOME/tmp/nginx/client/ \
--http-proxy-temp-path=$HOME/tmp/nginx/proxy/  \
--http-fastcgi-temp-path=$HOME/tmp/nginx/fcgi/ \
--with-http_flv_module \
--with-http_ssl_module \
--with-http_realip_module \

If the above runs without any errors then you’re good to make and make install

make  && make install

It’s important to note that at this stage the old instance of Nginx is running and you want to leave it there until you’ve replaced the new config ( that will epically fail in shared environment like Webfaction )

Replace your original config.

If you didn’t backup your config, then you’ll need to write a new one ( see this post towards the bottom for an example ). First though we’ll save the current one as the original–

cp ~/local/etc/nginx.conf{,.original}

Now replace the default with your backup–

mv ~/local/etc/nginx.conf.backup  ~/local/etc/nginx.conf.

Now you can restart Nginx.

nginx -s stop

And if you’re in doubt as to which version you’ve got you can confirm you’re running the right one –

$ nginx -v
nginx version: nginx/1.4.4