On Debian 13 / Ubuntu:
sudo apt update && sudo apt install nginx
This command updates the package list and installs the NGinX package from the default repositories.
On RHEL 10:
sudo dnf install nginx
This command installs NGinX from the default system repositories.
If you want to get the latest version, use the next variant or build your custom nginx.
To install the latest version of NGinX, you can use the official NGinX repository.
On Debian 13 / Ubuntu:
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo gpg --dearmor -o /usr/share/keyrings/nginx-archive-keyring.gpg
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) nginx" > /etc/apt/sources.list.d/nginx.list'
sudo sh -c 'echo "deb-src [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) nginx" >> /etc/apt/sources.list.d/nginx.list'
sudo apt update && sudo apt install nginx
On RHEL 10 (Stable):
sudo tee /etc/yum.repos.d/nginx.repo <<EOF
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/rhel/\$releasever/\$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
EOF
sudo dnf install nginx
On RHEL 10 (Mainline):
sudo tee /etc/yum.repos.d/nginx.repo <<EOF
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/rhel/\$releasever/\$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
EOF
sudo dnf install nginx
If you need the latest features or custom modules, you can build NGinX from source.
Install dependencies:
sudo apt update
sudo apt install build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev
sudo dnf groupinstall 'Development Tools'
sudo dnf install pcre pcre-devel zlib zlib-devel openssl openssl-devel
Download the latest NGinX source code from NGinX.org:
wget http://nginx.org/download/nginx-1.29.4.tar.gz
tar -zxvf nginx-1.29.4.tar.gz
cd nginx-1.29.4
Configure and compile NGinX:
./configure
make
sudo make install
Start NGinX:
sudo /usr/local/nginx/sbin/nginx
Building from source allows you to customize NGinX with specific modules and optimizations.
sudo systemctl start nginx
sudo systemctl restart nginx
sudo systemctl reload nginx # For reloading the config without downtime
sudo ufw allow 'Nginx Full'
sudo ufw status
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
See NGinX Hardening.
See NGinX Configuration.