How to Install Nginx on Debian 13
Nginx is a fast, lightweight web server that serves static content, terminates TLS, and proxies requests to application servers behind it. Debian 13 Trixie ships Nginx in its main apt repository, which makes the install a single command on a fresh system.
This guide explains how to install Nginx on Debian 13, open the firewall, manage the service with systemd, and create a basic server block for your first site.
Prerequisites
You will need a Debian 13 server with a sudo user. UFW should be installed and active so the install is firewalled by default.
Quick Reference
| Task | Command |
|---|---|
| Install Nginx | sudo apt install nginx |
| Allow HTTP and HTTPS in UFW | sudo ufw allow 'Nginx Full' |
| Start the service | sudo systemctl start nginx |
| Enable on boot | sudo systemctl enable nginx |
| Reload after config change | sudo systemctl reload nginx |
| Test configuration | sudo nginx -t |
| Show service status | systemctl status nginx |
| Site config directory | /etc/nginx/sites-available/ |
| Enabled-site symlinks | /etc/nginx/sites-enabled/ |
| Default document root | /var/www/html/ |
Step 1: Update the Package Index
Refresh apt so it sees the latest package metadata before the install:
sudo apt updateThe output lists the repositories that were checked. A clean run finishes without errors.
Step 2: Install Nginx
Install the nginx package:
sudo apt install nginxThe default install pulls in the nginx-common package, the systemd unit, and the standard set of modules. apt also creates the www-data user that owns the document root and runs the worker processes.
Confirm the version:
nginx -vnginx version: nginx/1.26.3
The exact version may differ as Debian publishes point updates, but 1.26.x is the version that ships with Debian 13 Trixie.
Step 3: Allow HTTP and HTTPS in UFW
The Nginx package registers application profiles with UFW. Allow both HTTP and HTTPS in one rule:
sudo ufw allow 'Nginx Full'Verify the rule is in place:
sudo ufw statusStatus: active
To Action From
-- ------ ----
Nginx Full ALLOW Anywhere
OpenSSH ALLOW Anywhere
If you only need HTTP for now, replace the rule with Nginx HTTP. Switch to Nginx Full later when you add TLS.
Step 4: Manage the Nginx Service with systemd
The Nginx package starts the service at install time and enables it for boot. Confirm both:
systemctl is-active nginx
systemctl is-enabled nginxactive
enabled
If the service is not running, start it:
sudo systemctl start nginxThe most common service operations are restart, reload, and status:
sudo systemctl restart nginx
sudo systemctl reload nginx
systemctl status nginxreload re-reads the configuration without dropping connections and is the right command after editing a server block. restart stops and starts the service, which is only needed when the binary itself changes.
Step 5: Verify the Default Page
Open a browser and visit the server’s IP, or use curl:
curl -I http://localhostHTTP/1.1 200 OK
Server: nginx/1.26.3
Content-Type: text/html
A 200 OK response confirms Nginx is serving the default page. The default document root is /var/www/html/ and contains an index.nginx-debian.html welcome page.
Step 6: Create Your First Server Block
Server blocks are how Nginx serves multiple sites from a single host. Create the document root for the new site:
sudo mkdir -p /var/www/example.com/html
sudo chown -R $USER:$USER /var/www/example.com/html
echo '<h1>Hello from example.com</h1>' | sudo tee /var/www/example.com/html/index.htmlCreate a server block file:
sudo nano /etc/nginx/sites-available/example.comPaste the following configuration and adjust the domain name:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/example.com/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}Enable the site by creating a symlink in sites-enabled:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/Test the configuration before reloading:
sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Reload Nginx so the new server block takes effect:
sudo systemctl reload nginxVisit the domain to verify the site loads. If the domain does not yet point at the server, edit /etc/hosts on a workstation or use curl --resolve example.com:80:SERVER_IP http://example.com/ to test.
Important Nginx Files and Directories
The default Debian layout splits configuration across several locations:
-
/etc/nginx/nginx.confis the main configuration file. -
/etc/nginx/sites-available/holds the server block templates. -
/etc/nginx/sites-enabled/holds symlinks to the active server blocks. -
/etc/nginx/snippets/is for shared configuration snippets such as TLS hardening. -
/var/log/nginx/access.logand/var/log/nginx/error.logare the log files. -
/var/www/html/is the default document root.
Troubleshooting
Default page does not load
Check that the service is running with systemctl status nginx. If it is not, run sudo nginx -t to spot configuration errors. UFW may also block port 80; confirm with sudo ufw status.
bind() to 0.0.0.0:80 failed (98: Address already in use)
Another web server is bound to port 80. Apache is the usual culprit on Debian. Stop it with sudo systemctl stop apache2 and disable it on boot with sudo systemctl disable apache2.
Server block returns 404
The symlink in sites-enabled is missing or points to the wrong file. List it with ls -l /etc/nginx/sites-enabled/. Recreate the symlink and reload Nginx.
nginx -t reports duplicate default_server
Two server blocks set listen 80 default_server. Only one can be the default. Remove the keyword from the new server block and reload.
Conclusion
Nginx on Debian 13 is one apt command away. Stick with the Debian package for general-purpose use, and switch to the upstream nginx.org repository when you need a feature only the latest mainline release supports.
![]()