The Short Answer
sudo apt update
sudo apt install nginx
systemctl status nginxThe 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 statusIf 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_ in a browser, or test from the server itself:
curl -I http://localhostThe 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_
Where the Files Are
| Path | What it holds |
|---|---|
nginx. | Main configuration |
sites- | One file per site |
sites- | Links to the active sites |
conf. | Extra settings files |
snippets/ | Reusable pieces |
/var/ | Default web root |
/var/ | 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 nginxRun 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 --reloadNginx 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/htmlby a server block insidenginx.confitself. - User: the worker processes run as
nginx. - SELinux: it stays enforcing. Web files need the web content label. Files created under
/var/wwwusually get it, but files moved in from elsewhere keep their old label;sudo restorecon -Rv /var/wwwresets it. A proxy to a local port such as 3000 needssudo setsebool -P httpd_. Do not turn SELinux off.can_ network_ connect 1
Next Steps
- Your own site: add a server block instead of editing the default page.
- HTTPS: get a certificate with Certbot for Nginx.
- PHP and a database: build a LEMP stack.
- An application: put Nginx in front of it as a reverse proxy.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations