How To Install Nginx and Set It Up As a Reverse Proxy
Goal
In this tutorial, you will install Nginx on an Ubuntu server, configure it as a reverse proxy in front of a local application, and verify the setup end-to-end.
Prerequisites
- A server/VPS running Ubuntu
- A non-root user with sudo privileges
- ufw firewall installed and active on the server
- A domain name you can point at the server (or /etc/hosts access on your local machine for testing without one)
- An application you want to expose, listening on a local port such as 3000
Let an AI agent do this for you
Copy a ready-made prompt for an AI coding assistant with terminal access to your server (Claude Code, Cursor, or similar) — it can carry out the steps below for you. Review what it plans to run before it executes anything.
Nginx is one of the most widely deployed web servers on Linux, and one of its most common jobs isn't serving static files at all — it's sitting in front of another process (a Node.js app, a Python app, a Java service, anything bound to a local port) and forwarding traffic to it. This is called a reverse proxy. It lets you run an application on an unprivileged, non-standard port, put Nginx on the standard web ports (80/443), and get TLS termination, logging, caching, and request buffering for free.
This tutorial covers installing Nginx from Ubuntu's official package repository, confirming it's running, opening the firewall correctly, and configuring it to reverse-proxy requests for a domain to a local application listening on port 3000.
Step 1 — Install Nginx
Ubuntu's default package repositories carry a current, well-maintained Nginx package, so a plain apt install is the right approach — no third-party repository needed. Update your package index first, then install:
sudo apt update
sudo apt install -y nginxThe package's postinstall step starts the nginx service and enables it to start on boot automatically, so no separate systemctl enable step is required.
Step 2 — Verify Nginx is running
Check the service state with systemctl:
systemctl status nginxYou're looking for Active: active (running) in the output. Press q to exit the pager if it drops you into one.
If the server has a public IP and port 80 is reachable, you can also confirm visually: open http://203.0.113.10 (substitute your server's real IP) in a browser. You should see the stock "Welcome to nginx!" page. That page comes from Nginx's default site config — you'll replace that config with your own in a later step.
Step 3 — Allow Nginx through the firewall
If ufw is active on the server, HTTP and HTTPS traffic need an explicit allow rule or Nginx will be unreachable from outside. The Nginx package registers an ufw application profile named 'Nginx Full' that opens both port 80 and port 443:
sudo ufw allow 'Nginx Full'“'Nginx Full' opens exactly ports 80 and 443 — nothing more. Don't disable ufw entirely to "make things work" — that removes protection from every other service running on this server, not just Nginx.”
Tricknowtech VPS Hosting
Dedicated KVM resources and full root access — deployed in under 60 seconds, no ticket required.
Ready to try it yourself?
Create a free account and follow along.