How to install the latest version of NGINX on Ubuntu Server 18.04
NGINX is one of the most popular web servers on the planet. It's reliable, scalable, and easy to use. But did you know, if you install NGINX from the default Ubuntu Server 18.04 repositories, the version you get is out of date? You don't want that. In fact, you probably want the most up-to-date stable release of the software.
How do you install such a version on the LTS release of Ubuntu Server? Let me show you how.
SEE: How to reduce user account lockouts and password resets (free PDF) (TechRepublic)
What you need
The only things you'll need to make this work are a running instance of Ubuntu Server 18.04 and a user account with sudo privileges. With those items at the ready, let's install.
Adding the repository
Fortunately, this doesn't have to be installed from source, as there is an official NGINX repository where the latest version can be found. To add this repository, create a new .list file with the command:
In that file, paste the following two lines:
Save and close the file.
Before installation, the NGINX public key must be added. To do this, issue the following commands:
Update and install
Once you have the key installed, update apt with the command:
On the off-chance you already have an older version of NGINX installed, remove it (and it's components) with the command:
If you did have NGINX installed (and your website server blocks configured), you might want to make a backup of your configuration file with the command:
Now it's time to install the latest version of NGINX. Do so with the command:
After the installation completes, start and enable NGINX with the commands:
To find out which version of NGINX was installed, issue the command:
You should see that (at least as of this writing), the version number is 1.17 (Figure A), which is the latest version (as opposed to 1.14 installed from the standard repositories).
Change process user and server blocks location
There's two small caveats to installing the latest version. Out of the box, the version from the NGINX repository sets nginx as the default process user. As an administrator (especially on Ubuntu Server), you are most likely accustomed to www-data being the web server process user. To set www-data as the default process users, open the NGINX configuration with the command:
Locate the line:
Change that option to:
Next we need to configure NGINX so that it will continue to read server block files from the sites-enabled directory (as this version of NGINX only reads them from /etc/nginx/conf.d/). To do this, add the following line to the http section of the configuration file (under the include /etc/nginx/conf.d/*.conf; line):
Save and close the configuration file. Reload NGINX (which will only re-read the configuration files, not restart the server) with the command:
NGINX is now ready to rock.
NGINX is one of the easiest to manage web servers on the planet, and getting the latest version installed helps to back up that opinion. Don't find yourself running an outdated version, especially considering getting the latest-greatest is such an easy task.