Install the packages required to connect the apt repository

sudo apt install curl gnupg2 ca-certificates lsb-release debian-archive-keyring

Now you need to import the official key that apt uses to authenticate packages. Download the key

curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

Check if the correct key was loaded:

gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg

The command output must contain the full key fingerprint

pub rsa2048 2011-08-19 [SC] [expires: 2027-05-24]
573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
uid nginx signing key <signing-key@nginx.com>

The command output may contain other keys used to sign packages.
To connect the apt repository for the stable version of NGINX, run the following command:

echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/debian `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list

To use packages from NGINX repository instead of Debian distributed, write:

echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
| sudo tee /etc/apt/preferences.d/99nginx

To install NGINX, run the following commands:

sudo apt update
sudo apt install nginx

Now let's check the installed version of NGINX

nginx -v

Now enable the NGINX service

sudo systemctl enable nginx

And start the NGINX service

sudo systemctl start nginx

And check NGINX status

sudo systemctl status nginx

Status must be active

nginx.service - nginx - high performance web server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; preset: enabled)
Active: active (running) since Fri 2025-01-10 20:18:24 EST; 12s ago
Docs: https://nginx.org/en/docs/
Process: 9440 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)

Now in the address bar of your browser type

http://localhost/

You should see a message

Welcome to nginx!

NGINX server installation is complete

How to set up a NGINX server for Debian 12 is written here