Upgrading Nginx to the latest version on Ubuntu
If you’re running nginx on an Ubuntu, you would soon find out that the default version of Ubuntu packed with the OS is really old.
All this means is that you need to be running the latest version of Nginx to avoid the security problems. This post is about how to do that.
The first thing is to find out which version are you on. Here’s how you do it.
$ nginx -v
It should show you something like.
nginx version: nginx/1.10.3 (Ubuntu)
Now that we know that we need to upgrade, the first thing to do is to backup your configuration.
$ sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.1.10.3.backup
Install the dependencies
$ sudo apt-get install software-properties-common python-software-properties
Add the repository for the stable version of Nginx
$ sudo add-apt-repository ppa:nginx/stable
Now update it
$ sudo apt-get update
Run install
$ sudo apt-get install nginx
When it asks you if you want to keep using the old config or get the new config like this.
Configuration file '/etc/nginx/nginx.conf'
==> Modified (by you or by a script) since installation.
==> Package distributor has shipped an updated version.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** nginx.conf (Y/I/N/O/D/Z) [default=N] ?
Select N(No). It will Install the new version of the current config files in /etc/nginx/sites-available
directory.
OR
Select Y(es) and get the latest config. It will remove current config files.
Check nginx version again.
$ nginx -v
Here’s what it should say.
nginx version: nginx/1.14.1
That’s it. Now you have the latest version of Nginx running on your server.