Nginx is an open-source web server designed for high-concurrency workloads — it can handle over 10,000 simultaneous connections and is widely used as both a web server and a reverse proxy.

This guide covers installing Nginx on Debian 12, configuring the UFW firewall to allow HTTP and HTTPS traffic, and setting up a virtual host to serve your own HTML content.

Quick Answer

Run sudo apt install nginx, then sudo ufw allow 'Nginx HTTP' and sudo ufw allow 'Nginx HTTPS' to open ports 80 and 443, then visit your machine’s IP address in a browser to confirm Nginx is running.

How to Install Nginx on Debian

Step 1: Update apt Packages

Update and upgrade the apt package index first to ensure you install the most current version of Nginx available in the Debian 12 repositories before starting the installation.

sudo apt update && sudo apt upgrade
sudo apt update and upgrade running on Debian 12 terminal

Step 2: Install Nginx

Install Nginx from the official Debian repositories. When prompted, type Y and press Enter to confirm the installation — apt will install Nginx and all required dependencies automatically.

sudo apt install nginx
sudo apt install nginx prompting Y to continue on Debian 12

Start the Nginx service, then check its status to confirm it’s running — the output should show Active (running) before you proceed to configure the firewall.

sudo systemctl start nginx
sudo systemctl status nginx
systemctl status nginx showing Active running on Debian 12

Step 3: Configure the UFW Firewall

List the available UFW application profiles to locate the Nginx entries — Nginx registers three profiles: Nginx HTTP (port 80), Nginx HTTPS (port 443), and Nginx Full (both ports).

sudo ufw app list
ufw app list showing Nginx HTTP, Nginx HTTPS, and Nginx Full profiles on Debian 12
UFW app list detail showing Nginx profile descriptions

Allow both HTTP and HTTPS traffic through the firewall, then enable UFW and verify the rules are active — the status output should show both Nginx HTTP and Nginx HTTPS as Allowed.

sudo ufw allow 'Nginx HTTP'
sudo ufw allow 'Nginx HTTPS'
sudo ufw enable
sudo ufw status
UFW rules showing Nginx HTTP and Nginx HTTPS added on Debian 12
ufw status showing Nginx HTTP and Nginx HTTPS allowed and UFW active on Debian 12

Step 4: Access the Nginx Default Page

Get your Debian machine’s IP address with ip addr, then type that IP in a browser on any machine on the same network — Nginx’s default welcome page confirms the server is running.

ip addr
ip addr output on Debian 12 showing local network IP address for Nginx access
Nginx default welcome page loaded in browser at Debian 12 IP address

How to Configure Nginx to Serve Your Own Site

Once Nginx is running, you can host custom web content by adding HTML files to the web root directory and updating the Nginx site configuration to point to your files.

Step 1: Review the Nginx configuration files inside /etc/nginx — the nginx.conf file controls global settings and sites-available/default defines the server blocks for hosted sites.

cd /etc/nginx && ls -1
ls -1 output inside /etc/nginx showing nginx.conf and sites-available directory

Step 2: Create an HTML file in the web root directory at /var/www/html/ — this is the directory the default Nginx site configuration serves files from when a request comes in.

nano /var/www/html/mypage.html

Add your HTML content to the file, save with Ctrl+S, and exit with Ctrl+X. Then open the default site config and add your filename to the index directive in the location block.

<!DOCTYPE html>
<html>
<head>
    <title>My Nginx Page</title>
</head>
<body>
    <h1>Served by Nginx on Debian 12!</h1>
</body>
</html>
sites-available default config with mypage.html added to the index directive

Step 3: Test the Nginx configuration for syntax errors, reload the server to apply changes, then visit your IP address in the browser to confirm your page is being served.

sudo nginx -t
sudo nginx -s reload
nginx -t output showing configuration file syntax is ok and test is successful
Browser showing custom HTML page content served by Nginx on Debian 12 IP address

When to Use Nginx on Debian

Use Nginx when you need to serve a website, host a web application, or set up a reverse proxy for backend services — it outperforms Apache under high concurrency with lower memory usage.

It’s the standard choice for Debian-based production servers running Laravel, Django, Node.js, or any application requiring HTTP/HTTPS ingress with TLS termination and static asset serving.

For simple local testing or development, Nginx is also useful as a quick way to serve static files over HTTP on your local network without needing a full production setup.

Related Guides

These Linux server and networking guides cover related tasks you may need when setting up and managing Nginx on a Debian machine.