You don't want an out-of-date web server serving up your sites. Get the latest version of NGINX installed with ease 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:
sudo nano /etc/apt/sources.list.d/nginx.list
In that file, paste the following two lines:
deb [arch=amd64] http://nginx.org/packages/mainline/ubuntu/ bionic nginx deb-src http://nginx.org/packages/mainline/ubuntu/ bionic nginx
Save and close the file.
Before installation, the NGINX public key must be added. To do this, issue the following commands:
wget http://nginx.org/keys/nginx_signing.key sudo apt-key add nginx_signing.key
Update and install
Once you have the key installed, update apt with the command:
sudo apt-get update
On the off-chance you already have an older version of NGINX installed, remove it (and it's components) with the command:
sudo apt remove nginx nginx-common nginx-full nginx-core
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:
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.old
Now it's time to install the latest version of NGINX. Do so with the command:
sudo apt-get install nginx -y
After the installation completes, start and enable NGINX with the commands:
sudo systemctl start nginx sudo systemctl enable nginx
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:
sudo nano /etc/nginx/nginx.conf
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:
sudo systemctl reload nginx
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.
- How to secure NGINX with Let's Encrypt (TechRepublic)
- How to build NGINX with TLS support on Ubuntu Server 18.04 (TechRepublic)
- How to create NGINX server blocks on Ubuntu 18.04 (TechRepublic)
- F5 Networks to acquire NGINX (ZDNet)
- DevOps: A cheat sheet (TechRepublic)
- Programming languages and developer career resources coverage (TechRepublic on Flipboard)
- 10 free alternatives to Microsoft Word and Excel (TechRepublic download)
- The 10 most important iPhone apps of all time (Download.com)
- It takes work to keep your data private online. These apps can help (CNET