Install Nginx on Linux

Contents
Debian and Ubuntu
Rocky Linux, RHEL, AlmaLinux and Fedora
Alpine Linux
Check that Nginx answers
Open the firewall
Where the files are
Start, stop and reload
Newer versions from nginx.org
Remove Nginx

Every major Linux distribution packages Nginx, so the install is one command of the package manager. The distributions differ in what happens after it: which version you get, whether the service starts by itself, and where the configuration and the web root are.

The outputs come from fresh containers of Debian 13, Ubuntu 24.04, Rocky Linux 9.8, Fedora 44 and Alpine 3.24, checked on 26 October 2026; the systemctl output is from an Ubuntu 20.04 machine. Tools used here: curl, systemctl.

Debian and Ubuntu

On Debian and Ubuntu Nginx comes from the distribution repositories. Each has its own page with the versions of every release, ufw and the modules: Install Nginx on Debian and Install Nginx on Ubuntu. In short, refresh the package lists first:

sudo apt update

sudo apt install nginx

The end of the output on Debian 13. The 47 packages are Nginx, curl and procps with everything they need in an empty container; a normal server already has most of them:

0 upgraded, 47 newly installed, 0 to remove and 1 not upgraded. Need to get 11.1 MB of archives. After this operation, 33.6 MB of additional disk space will be used. … Setting up nginx-common (1.26.3-3+deb13u10) ... Setting up nginx (1.26.3-3+deb13u10) ...

The package starts Nginx right away and enables it at boot. Enabling it once more does no harm and shows that systemd knows the service:

sudo systemctl enable nginx

Synchronizing state of nginx.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable nginx

Check the version:

nginx -v

nginx version: nginx/1.24.0 (Ubuntu)

That is Ubuntu 24.04. Ubuntu 22.04 installs 1.18.0, Debian 13 installs 1.26.3 and prints just nginx/1.26.3, without the distribution name.

Rocky Linux, RHEL, AlmaLinux and Fedora

Rocky Linux, AlmaLinux, RHEL, CentOS Stream and Fedora install Nginx with dnf:

sudo dnf install nginx

Unlike Debian, the package neither starts Nginx nor enables it at boot. Do both in one command:

sudo systemctl enable --now nginx

Rocky Linux 9.8 installs Nginx 1.20.1 by default. Newer versions come as module streams:

dnf module list nginx

Name Stream Profiles Summary nginx 1.22 common [d] nginx webserver nginx 1.24 common [d] nginx webserver nginx 1.26 common [d] nginx webserver

Enable a stream before the install, and dnf takes Nginx from it:

sudo dnf module enable nginx:1.26

sudo dnf install nginx

nginx -v

nginx version: nginx/1.26.3

Fedora has no streams and follows the current releases: Fedora 44 installs 1.30.6.

On CentOS 7 Nginx came from the EPEL repository (yum install epel-release, then yum install nginx). CentOS 7 reached its end of life in June 2024 and its repositories are archived, so new servers use Rocky Linux or AlmaLinux instead.

Alpine Linux

Alpine is common as a base for Docker images. Install as root:

apk add nginx

Alpine 3.24 installs 1.30.6. Unlike the other distributions, its default site answers 404 to every request, on purpose. The file is

/etc/nginx/http.d/default.conf

# This is a default site configuration which will simply return 404, preventing # chance access to any other virtualhost. server { listen 80 default_server; listen [::]:80 default_server; # Everything is a 404 location / { return 404; } # You may need this to prevent return 404 recursion. location = /404.html { internal; } }

To serve files, replace return 404; with a root directive, for example root /srv/www;, and put an index.html into that folder. On a system with OpenRC start Nginx now and at boot:

rc-update add nginx default

rc-service nginx start

Banner image

Check that Nginx answers

Ask for the headers of the start page:

curl -I http://localhost/

HTTP/1.1 200 OK Server: nginx/1.24.0 (Ubuntu) Date: Mon, 26 Oct 2026 08:16:45 GMT Content-Type: text/html Content-Length: 615 Last-Modified: Mon, 26 Oct 2026 08:16:31 GMT Connection: keep-alive ETag: "6adf0c5f-267" Accept-Ranges: bytes

The page itself is the welcome page:

curl -s http://localhost/ | grep title

<title>Welcome to nginx!</title>

Debian 13 sends Server: nginx without the version. Alpine answers HTTP/1.1 404 Not Found until you change its default site, as shown above.

Nginx runs one master process as root and worker processes as an unprivileged user, by default one worker per CPU core:

ps -eo user,cmd | grep [n]ginx:

root nginx: master process nginx www-data nginx: worker process www-data nginx: worker process www-data nginx: worker process www-data nginx: worker process

Open the firewall

On Ubuntu the Nginx package adds three profiles to UFW: Nginx HTTP (port 80), Nginx HTTPS (port 443) and Nginx Full (both). Allow both ports:

sudo ufw allow 'Nginx Full'

On Rocky Linux, RHEL, AlmaLinux and Fedora firewalld is on by default and blocks port 80 until you open it:

sudo firewall-cmd --permanent --add-service=http --add-service=https

sudo firewall-cmd --reload

Where the files are

The main file is /etc/nginx/nginx.conf everywhere. Where your own sites go differs:

Debian, UbuntuRocky, RHEL, FedoraAlpine
Your sites/etc/nginx/sites-available/, linked into sites-enabled//etc/nginx/conf.d/*.conf/etc/nginx/http.d/*.conf
Default web root/var/www/html/usr/share/nginx/htmlnone, the default site answers 404
Worker userwww-datanginxnginx
Logs/var/log/nginx//var/log/nginx//var/log/nginx/

Debian and Ubuntu also read /etc/nginx/conf.d/, but their own default site lives in sites-enabled:

ls -l /etc/nginx/sites-enabled

total 0 lrwxrwxrwx 1 root root 34 Oct 26 08:00 default -> /etc/nginx/sites-available/default

Nginx itself tells where it looks for its files:

nginx -V 2>&1 | tr ' ' '\n' | grep path

--conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=stderr --pid-path=/run/nginx.pid

That is Ubuntu 24.04. The error log is set to stderr only for the time before Nginx reads its configuration; after that the error_log directive in nginx.conf applies.

Start, stop and reload

systemd controls the service on every distribution here except Alpine:

sudo systemctl stop nginx

sudo systemctl start nginx

sudo systemctl restart nginx

After a change to the configuration test it first:

sudo nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

and only then reload. A reload keeps Nginx answering: new workers start with the new configuration and the old ones finish their requests.

sudo systemctl reload nginx

The first server block and a reverse proxy are on the Nginx page.

Newer versions from nginx.org

The Nginx developers publish their own packages for Debian, Ubuntu, RHEL and its rebuilds, SLES and Alpine, with the current stable and mainline versions: 1.30.6 and 1.31.8 on 26 October 2026. The setup for each distribution is on nginx.org/en/linux_packages.html: add the signing key and the repository, then install nginx as above.

These packages use the RHEL layout on every distribution: sites go to /etc/nginx/conf.d/, the web root is /usr/share/nginx/html and the workers run as nginx. On Debian and Ubuntu there is no sites-enabled folder with them.

Remove Nginx

On Debian and Ubuntu remove keeps the configuration in /etc/nginx, so a later install picks it up again:

sudo apt remove nginx

To delete the configuration too, purge both packages:

sudo apt purge nginx nginx-common

Purge deletes /etc/nginx and the logs in /var/log/nginx. Everything in /var/www stays, your sites and the welcome page index.nginx-debian.html alike.

On Rocky Linux, RHEL, AlmaLinux and Fedora:

sudo dnf remove nginx

On Alpine:

apk del nginx

Article author: Klavdiya Kondakova

Related articles
Install Nginx
Install Nginx on Debian
Install Nginx on Ubuntu
Install Nginx on Windows
Install Nginx on FreeBSD, OpenBSD and macOS
Nginx
Banner image

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: