If you followed my previous guides for LEMP Install NGINX PHP7 MySQL on Ubuntu 16.04 Server then you probably installed NGINX from the Ubuntu repo. Unfortunately, the version in the Ubuntu repo doesn’t get updated very often, so depending on how long ago you installed NGINX, you might be pretty far behind in versions. Newer versions contain performance improvements along with security fixes, so it is important that you keep your server updated.
You can run sudo nginx -v to check what version you’re on. As of this article, the current stable branch is 1.12.x. Luckily, upgrading is fairly easy and usually doesn’t break anything. You need to add a new repo, then NGINX can be upgraded every time you run your sudo apt upgrade command.
Running nginx -v, you’ll probably see something similar to this: sudo nginx -V nginx version: nginx/1.10.3 (Ubuntu)
The first steps you’ll want to do is backing up your current NGINX configs. You can run these two commands to create a backup directory and copy your config files over to it: sudo mkdir /etc/nginx-backup/ sudo cp -r /etc/nginx/* /etc/nginx-backup/
Next we need to add the repository. For this, you’ll need to install software-properties-common if it’s not already installed. Run this command to make sure it is installed: sudo apt-get install software-properties-common
Now we’ll add the NGINX repo by running these commands: nginx=stable sudo add-apt-repository ppa:nginx/$nginx
You should get an output similar to this and you’ll need to press Enter to approve adding it:
This PPA contains the latest Stable Release version of the nginx web server software.
The following architectures are supported; if your arch doesn't match this list then the PPA is not supporting that architecture: * i386 * amd64 * armhf * arm64 * ppc64el
The following releases of Ubuntu (including in-development releases) are supported in this PPA: * Trusty (14.04) * Xenial (16.04) * Yakkety (16.10) * Zesty (17.04) * Artful (17.10 - in development!)
The following releases of Ubuntu are no longer supported, and have had their packages removed from the PPA: * Lucid (10.04) * Maverick (10.10) * Natty (11.04) * Oneiric (11.10) * Quantal (11.10) * Raring (13.04) * Saucy (13.10) * Utopic (14.10) * Vivid (15.04) * Wily (15.10) More info: https://launchpad.net/~nginx/+archive/ubuntu/stable Press [ENTER] to continue or ctrl-c to cancel adding it
gpg: keyring `/tmp/tmphecc_aoy/secring.gpg' created gpg: keyring `/tmp/tmphecc_aoy/pubring.gpg' created gpg: requesting key C300EE8C from hkp server keyserver.ubuntu.com gpg: /tmp/tmphecc_aoy/trustdb.gpg: trustdb created gpg: key C300EE8C: public key "Launchpad Stable" imported gpg: no ultimately trusted keys found gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1) OK
Now we’ll want to update the available packages by running: sudo apt-get update
Finally, we’ll want to run a full upgrade which will include NGINX and all of its add-ons: sudo apt-get full-upgrade
You’ll be prompted to use a new config files twice, you’ll want to answer N to those for now to keep your current versions.
Now when you run sudo nginx -v you should see a new version.
Finally, you’ll want to edit your /etc/nginx/nginx.conf file and add this line just below the pid line near the top: include /etc/nginx/modules-enabled/*.conf;
Next, run sudo nginx -t to test the new config and make any changes you need in order for it to pass the test.