A nginx reverse proxy setup puts Nginx in front of your apps and lets visitors reach them through normal domain names instead of IP addresses and port numbers. Instead of sharing http://203.0.113.10:3000, visitors type app.example.com and Nginx forwards the request to the app on port 3000 behind the scenes.
This tutorial builds that setup from scratch: a small test app on a local port, a proxy block for it, a live test, and HTTPS at the end. You need SSH access and basic text-file editing, nothing more.
What a Reverse Proxy Does, in Plain Terms
Think of a reverse proxy as a reception desk. Visitors talk to the desk, and the desk passes each request to the right room. Visitors never see the rooms directly. In server terms, Nginx is the desk, and each app on a local port is a room.
That layout buys you three things: several apps share ports 80 and 443, HTTPS lives in one place instead of inside every app, and you can restart one app without touching the others.
A reverse proxy is not the same as a normal website block. A normal block serves files from disk, while a proxy block forwards requests to an app that generates responses on the fly. Static sites suit a normal block; an app with its own server process, like a Node.js app on port 8080, needs a proxy block.
When to Use a Proxy, and When Not To
Use a proxy for apps that listen on their own ports: a Node.js app, a Python web app, a self-hosted dashboard, or a Docker container with a published port. Use it too when several apps share one server, such as app.example.com and api.example.com.
Skip a proxy when you only serve static files: HTML, CSS, and images load faster straight from Nginx, with no app process in the middle. Skip it too if you are happy sharing a port number in the URL, though most production setups prefer a clean domain name.
For a visual interface instead of config files, a Docker panel is another route: the guide on how to set up Nginx Proxy Manager with Docker for multiple sites covers it. This tutorial sticks to plain config files, which teach you what the panel does underneath.
Plan Your Nginx Reverse Proxy Setup Before You Write Config
Note three facts before you touch a config file: the app domain, its port, and whether it runs on the same server as Nginx. This tutorial assumes one server, one app on port 3000, and app.example.com. Replace those values with your own.
Point the domain DNS A record at your server IP first; DNS changes can take a while to spread. While you wait, you can still test locally with curl, as shown later.
If you later add a second app, the pattern repeats: a second domain, a second port, and a second block. Nothing in the first block changes. A comparison like Traefik vs Nginx Proxy Manager for Docker beginners shows how much of this wiring each tool does for you.
Step 1: Get a Test App Running on Port 3000
Install Nginx first if it is not already on the server:
sudo apt update
sudo apt install nginx -y
sudo systemctl enable nginx
sudo systemctl start nginx
Next, start something for Nginx to forward to. If you already have an app, skip this step and note its port. If not, a one-line Python server works as a stand-in on port 3000:
cd /var/www
python3 -m http.server 3000 --bind 127.0.0.1 > /tmp/test-app.log 2>&1 &
curl http://127.0.0.1:3000/
The curl command should return a directory listing or page content. A connection error means the test app did not start, so there is nothing for Nginx to forward to yet. Fix that first: a proxy block pointing at a dead port returns a 502 error, the most common beginner failure here.
Bind to 127.0.0.1 so the app accepts connections only from the same server: visitors must come through Nginx, not directly on port 3000. For a real app, check its docs for the localhost bind option.
Step 2: Write the Proxy Block
Create a new block file for the app domain. The nginx proxy_pass config below is the core of the whole tutorial: one line forwards requests to the app, and the header lines pass the visitor details along so the app sees the real visitor, not just Nginx.
sudo nano /etc/nginx/sites-available/app.example.com
server {
listen 80;
listen [::]:80;
server_name app.example.com;
access_log /var/log/nginx/app.example.com.access.log;
error_log /var/log/nginx/app.example.com.error.log;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
Read the location block line by line. The proxy_pass line is the destination. Host tells the app which domain the visitor asked for. X-Real-IP and X-Forwarded-For carry the visitor IP, so app logs show real visitors instead of 127.0.0.1 for every request. X-Forwarded-Proto tells the app whether the visitor used HTTP or HTTPS. The Upgrade lines serve apps that use WebSockets, such as live dashboards; a plain app ignores them without harm.
Enable the block and test the config before reloading, the same way you would for any Nginx site:
sudo ln -s /etc/nginx/sites-available/app.example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Now visit http://app.example.com in a browser. You should see your app, served without a port number in the address bar. A welcome page means the request hit the default block: server_name does not match the domain you typed, or DNS still points elsewhere. A 502 Bad Gateway page means Nginx runs but the app is not answering on port 3000: restart the app and repeat the curl test from Step 1.
Step 3: Test, Secure, and Add a Second App
Test three things before you call the setup done: curl the app through Nginx from the server and check for a 200 response, load the domain in a browser from another network to rule out a local DNS shortcut, and check the error log at /var/log/nginx/app.example.com.error.log after a few real requests.
curl -I http://app.example.com/
sudo tail -20 /var/log/nginx/app.example.com.error.log
Next, add HTTPS. Without it, visitor traffic travels in plain text between the browser and Nginx, even though the Nginx-to-app hop stays inside the server. The guide on how to install a free Let’s Encrypt SSL certificate on Nginx with Certbot walks through that step, and Certbot can add the HTTPS listener automatically. After HTTPS is live, keep the X-Forwarded-Proto header: it tells your app visitors arrived over HTTPS.
For a second app, copy the pattern: a new block file, a new domain, and a new port. That is how a nginx reverse proxy multiple apps layout grows, one block per app. A comparison of Cloudflare Tunnel vs Nginx Proxy Manager vs Traefik for reverse proxies can help if you later want to expose apps without opening ports at all.
One more layer is worth adding once traffic grows: rate limiting. A public-facing proxy attracts bots that hammer login pages and scrape content. The guide on how to rate limit Nginx to stop brute force and scraping bots shows how to cap requests per visitor in these same block files.
Fixing the Errors You Will Meet First
A 502 Bad Gateway error means Nginx is up and the app is not answering. Check that the app process runs, listens on the port in proxy_pass, and accepts local connections. A port mismatch of even one digit produces a 502 with no other visible clue.
A 404 from your app, rather than from Nginx, means the proxy works and the app itself cannot find the path: check the app logs for that one. A 404 from Nginx with its default error page usually means the request hit the wrong block, so re-check server_name and the sites-enabled symlink.
Redirect loops happen when the app thinks visitors use HTTP while Nginx serves HTTPS, so the app keeps redirecting to HTTPS. The fix is usually the X-Forwarded-Proto header, which this guide includes, plus an app setting that tells it to trust proxy headers. Check your app docs for a trusted proxy setting and turn it on.
WebSocket features that connect then drop almost always trace back to missing Upgrade headers. Compare your location block against Step 2 and confirm both Upgrade lines are present. A reverse proxy nginx beginners guide that skips those headers leaves live features half broken, so keep them even if your first app does not need them yet.
When the setup works, keep a short checklist for each new app: DNS points at the server, the app answers on its local port, the block passes nginx -t, the domain loads without a port number, and HTTPS is active. Run through that list for every app, and the nginx proxy headers forwarded setup stays predictable as the server grows.