If you installed Nginx from the default Ubuntu Server 18.04 repositories, the version you get is probably out of date. For security reasons, you should have the latest version always up to date.
To update Nginx to the latest version follow the next steps:
- Download from Nginx repository where the latest version can be found. Create a new .list file with the command:
//Open nginx.conf sudo nano /etc/apt/sources.list.d/nginx.list
// sudo nano /etc/apt/sources.list.d/nginx.list //
- Inside the file paste the following 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 (nano editor – ctrl + x)
- Before installation an Nginx public key must be added by running the following 2 commands.
// wget http://nginx.org/keys/nginx_signing.key //
// sudo apt-key add nginx_signing.key //
- After the key installation, update with the command:
// sudo apt-get update //
- If you have an older Nginx version installed make a backup first of the configuration before removing it completely.
// sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.old //
- Once that’s done proceed with the removal
// sudo apt remove nginx nginx-common nginx-full nginx-core //
- Now you can install the new Nginx version
// sudo apt-get install nginx -y //
- After the installation you need to start and enable the new Nginx
// sudo systemctl start nginx //
// sudo systemctl enable nginx //
- Test new Nginx version
// nginx -v //
- Now we are going to change the process user and server blocks location. 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: user nginx; Change that option to:
// user www-data; //
- Configure NGINX so that it will continue to read server block files from the sites-enabled directory. Look for the configuration file (/etc/nginx/nginx.conf) and add the following line inside the http bracket and above /etc/nginx/conf.d/*.conf; line.
// include /etc/nginx/sites-enabled/*; //
- Reload Nginx
// sudo systemctl reload nginx //
Any questions? Reach out… sophie(at)cybermaterial.com //