Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

The Short Answer

sudo apt update
sudo apt install nginx
systemctl status nginx

The package comes from the distribution's own repository, so it receives security updates with the rest of the system. On Ubuntu and Debian the service starts as soon as the installation finishes and is enabled at boot. The status output should say active (running). nginx -v prints the installed version.

Open the Firewall

On Debian and Ubuntu the package adds application profiles for ufw. Ubuntu has ufw installed; on Debian install it first with sudo apt install ufw. List the profiles:

sudo ufw app list

"Nginx HTTP" opens port 80, "Nginx HTTPS" opens port 443, and "Nginx Full" opens both; newer packages also list "Nginx QUIC". Allow both ports if you plan to add a certificate:

sudo ufw allow 'Nginx Full'
sudo ufw status

If the profiles are not listed, open the ports by number with sudo ufw allow 80/tcp and sudo ufw allow 443/tcp. If ufw is not active yet, allow your SSH port first (sudo ufw allow 22/tcp) and only then run sudo ufw enable, or the firewall can cut off your own session. If your provider's control panel has a firewall in front of the server, open the same ports there.

Check the Default Page

Open http://your_server_ip in a browser, or test from the server itself:

curl -I http://localhost

The first line should report status 200, and the Server header names nginx. In a browser you see the Nginx welcome page. On Debian and Ubuntu that page is the file /var/www/html/index.nginx-debian.html. If curl on the server works but the browser cannot connect, a firewall is still closed; see ERR_CONNECTION_REFUSED.

Where the Files Are

PathWhat it holds
nginx.confMain configuration
sites-available/One file per site
sites-enabled/Links to the active sites
conf.d/Extra settings files
snippets/Reusable pieces
/var/www/htmlDefault web root
/var/log/nginx/Access and error logs

The first five entries are under /etc/nginx/. This is the Debian and Ubuntu layout, where the worker processes run as the www-data user. The full picture is in where is the Nginx configuration file.

Manage the Service

sudo nginx -t
sudo systemctl reload nginx
sudo systemctl enable nginx

Run nginx -t after every change, then reload. A reload applies the new configuration only if it is valid, and the running server keeps working with the old one if it is not. A restart with a broken file stops Nginx and leaves the site down. See how to start, stop, and reload Nginx.

Install on AlmaLinux and Rocky Linux

sudo dnf install nginx
sudo systemctl enable --now nginx
sudo firewall-cmd --permanent --add-service=http --add-service=https
sudo firewall-cmd --reload

Nginx comes from the AppStream repository. The package is not enabled or started after installation, which is why the second line enables and starts it. The layout differs from Debian:

  • Sites: one file per site in /etc/nginx/conf.d/, ending in .conf. There is no sites-available folder.
  • Default page: served from /usr/share/nginx/html by a server block inside nginx.conf itself.
  • User: the worker processes run as nginx.
  • SELinux: it stays enforcing. Web files need the web content label. Files created under /var/www usually get it, but files moved in from elsewhere keep their old label; sudo restorecon -Rv /var/www resets it. A proxy to a local port such as 3000 needs sudo setsebool -P httpd_can_network_connect 1. Do not turn SELinux off.

Next Steps

Was this answer helpful?
Loading...