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

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

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

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


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


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


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

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>

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


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.