Install GPG:
sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring -y
Download repo key:
curl -fsSL https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
Generate .list file for the repo config:
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/mainline/ubuntu $(lsb_release -cs) nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
Update & install nginx:
sudo apt update && sudo apt install nginx -y
Enable service init on startup:
sudo systemctl enable nginx