Step 1 – Connect to the server via SSH and install the required software
sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring
result:
root@tutorialspots ~ # sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring Reading package lists... Done Building dependency tree... Done Reading state information... Done lsb-release is already the newest version (11.1.0ubuntu4). ubuntu-keyring is already the newest version (2021.03.26). ca-certificates is already the newest version (20230311ubuntu0.22.04.1). ca-certificates set to manually installed. curl is already the newest version (7.81.0-1ubuntu1.15). gnupg2 is already the newest version (2.2.27-3ubuntu2.1). 0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
Step 2 – Import nginx signing key for apt
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
result:
root@tutorialspots ~ # curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \ > | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1561 100 1561 0 0 24691 0 --:--:-- --:--:-- --:--:-- 24777
Step 3 -Create source.list file for apt:
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
Step 4 -Pin the repository to ensure nginx packages are installed instead of packages provided by Ubuntu
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
| sudo tee /etc/apt/preferences.d/99-nginx
Step 5 – Update apt:
sudo apt update
result:
root@tutorialspots ~ # sudo apt update Hit:1 http://mirror.hetzner.com/ubuntu/packages jammy InRelease Hit:2 http://mirror.hetzner.com/ubuntu/packages jammy-updates InRelease Hit:3 http://mirror.hetzner.com/ubuntu/packages jammy-backports InRelease Hit:4 http://mirror.hetzner.com/ubuntu/packages jammy-security InRelease Get:5 http://nginx.org/packages/ubuntu jammy InRelease [3,587 B] Hit:6 http://de.archive.ubuntu.com/ubuntu jammy InRelease Hit:7 http://de.archive.ubuntu.com/ubuntu jammy-updates InRelease Hit:8 http://de.archive.ubuntu.com/ubuntu jammy-backports InRelease Get:9 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB] Get:10 http://nginx.org/packages/ubuntu jammy/nginx amd64 Packages [14.4 kB] Fetched 128 kB in 1s (210 kB/s) Reading package lists... Done Building dependency tree... Done Reading state information... Done 4 packages can be upgraded. Run 'apt list --upgradable' to see them.
Step 6– Install nginx
sudo apt install nginx
result:
... (Reading database ... 57747 files and directories currently installed.) Preparing to unpack .../nginx_1.24.0-1~jammy_amd64.deb ... ---------------------------------------------------------------------- Thanks for using nginx! Please find the official documentation for nginx here: * https://nginx.org/en/docs/ Please subscribe to nginx-announce mailing list to get the most important news about nginx: * https://nginx.org/en/support.html Commercial subscriptions for nginx are available on: * https://nginx.com/products/ ---------------------------------------------------------------------- Unpacking nginx (1.24.0-1~jammy) ... Setting up nginx (1.24.0-1~jammy) ... Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /lib/systemd/system/nginx.service. Processing triggers for man-db (2.10.2-1) ... Scanning processes... Scanning candidates... Scanning processor microcode... Scanning linux images... The processor microcode seems to be up-to-date. Restarting services... Service restarts being deferred: /etc/needrestart/restart.d/dbus.service systemctl restart getty@tty1.service systemctl restart networkd-dispatcher.service systemctl restart systemd-logind.service systemctl restart unattended-upgrades.service No containers need to be restarted. No user sessions are running outdated binaries. No VM guests are running outdated hypervisor (qemu) binaries on this host.
Step 7 – Check and test
systemctl restart nginx
nginx -v
curl -I 127.0.0.1
result:
... root@tutorialspots ~ # nginx -v nginx version: nginx/1.24.0 root@tutorialspots ~ # curl -I 127.0.0.1 HTTP/1.1 200 OK Server: nginx/1.24.0 Date: Sun, 25 Feb 2024 17:44:51 GMT Content-Type: text/html Content-Length: 615 Last-Modified: Tue, 11 Apr 2023 01:45:34 GMT Connection: keep-alive ETag: "6434bbbe-267" Accept-Ranges: bytes