Upgrade Running Nginx on Amazon Linux

Upgrade Running Nginx on Amazon Linux

If you’d like to upgrade running Nginx on your Unix server version read on for some information on how to achieve it.

nginx

Nginx Web Server

Digital Ocean has a fairly complex tutorial on upgrading Nginx without losing client connections. Here’s an alternate method which seems to automate their recommendation, though I can’t say for sure that it actually works, but Nginx does seem to be upgraded after I followed these steps. Of course you’ll need to alter the versions¬†to match what’s available when you do this.

Download the software

wget http://nginx.org/download/nginx-1.11.13.tar.gz
git clone https://github.com/openresty/headers-more-nginx-module.git
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz

Unpack the software

tar -xzf nginx-1.11.13.tar.gz
tar -xzf ngx_cache_purge-2.3.tar.gz

Build the software

cd nginx-1.11.13
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_gunzip_module --with-http_gzip_static_module --with-threads --with-file-aio --with-http_v2_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=native' --add-module=../ngx_cache_purge-2.3 --add-module=../headers-more-nginx-module

make
make install
make upgrade # (this swaps to the new version of Nginx)
make clean # (optional, removes unnecessary files for the build)

You can then delete the whole tree if you like. I delete the uncompressed versions and keep the downloaded files, so I know what I build.

Here’s the output from “make upgrade”

make upgrade
/usr/sbin/nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
kill -USR2 `cat /var/run/nginx.pid`
sleep 1
test -f /var/run/nginx.pid.oldbin
kill -QUIT `cat /var/run/nginx.pid.oldbin`

There you have it, a simple way to  upgrade a running Nginx install, hopefully not dropping connections.

Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *