promisepreston
12/11/2019 - 12:21 PM

Install and Setup Nginx on Ubuntu 18.04

Install and Setup Nginx on Ubuntu 18.04

Install the Prerequisites

sudo apt install curl gnupg2 ca-certificates lsb-release

Set up the Apt Repository

Do not set up the apt repository for stable nginx packages by running the following command below if your architecture is amd64 (64 bit):

echo "deb http://nginx.org/packages/ubuntulsb_release -csnginx" \ | sudo tee /etc/apt/sources.list.d/nginx.list

As you will run into this error:

N: Skipping acquire of configured file 'nginx/binary-i386/Packages' as repository 'http://nginx.org/packages/ubuntu bionic InRelease' doesn't support architecture 'i386'

To check the architecture of your Ubuntu machine, simply run the command below: uname -a

The shortened copy of expected response for 32 and 64 bit achitectures should be like this:

1. Linux Preston-PC 5.0.0-31-generic i686 athlon i386
   # for 32 Bit architecture
2. Linux Preston-PC 5.0.0-31-generic x86_64 x86_64 x86_64
   # for 64 Bit Architecture

Import Official Nginx Signing Key

Next, import an official nginx signing key so apt could verify the packages authenticity:

curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -

Verify that you now have the proper key:

sudo apt-key fingerprint ABF5BD827BD9BF62

The output should contain the full fingerprint 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62 as follows:

pub   rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
      573B FD6B 3D8F BC64 1079  A6AB ABF5 BD82 7BD9 BF62
uid           [ unknown] nginx signing key <signing-key@nginx.com>

Install Nginx

To install nginx, run the following commands:

sudo apt update
sudo apt install nginx

Start Nginx Service

We can start, stop, monitor and restart nginx service with the systemd init system by running the command below:

sudo systemctl start nginx
sudo systemctl status nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl reload nginx

References

  1. How To Install Nginx on Ubuntu 18.04