An Nginx reverse proxy server sits between visitors and your backend application, taking each request, forwarding it to the right app server, and returning the response. This guide shows how to install Nginx, write a working reverse proxy configuration with proxy_pass, forward the headers your app needs, add load balancing and WebSockets, and put HTTPS in front of it all. It also covers Nginx Proxy Manager, the Docker-based GUI that does the same job without hand-written config files.

Photo via Pexels. A reverse proxy is the front door of your setup: visitors talk to Nginx, and Nginx talks to your app.
What Is an Nginx Reverse Proxy?
A reverse proxy is a server that receives requests from clients and forwards them to backend servers on their behalf. Nginx is one of the most widely used reverse proxies because it is fast, stable, and free. An Nginx proxy server can also serve static files, terminate TLS, cache responses, and balance load across several backends, and using Nginx as a reverse proxy is the standard way to put an app behind it. When you put Nginx in front of an app, visitors only ever talk to Nginx on ports 80 and 443, and your application server stays hidden behind it, listening on a local port such as 3000 or 8000.
That separation brings several benefits. The backend is not exposed directly to the internet, so an attacker cannot reach it without passing through Nginx first. TLS is handled in one place, so each app behind the proxy does not need its own certificate. One Nginx server can host several apps on different domains, routing each domain to a different backend. And if one backend goes down, Nginx can send traffic to the others.
The difference from a forward proxy is worth stating once, because the two are often confused. A forward proxy acts for the client and hides the client from the server. A reverse proxy acts for the server and hides the server from the client. If you want to compare the two in depth, including when each one fits, read our guide to forward vs reverse proxy. For the developer-side view, including environment variables and per-tool settings, see our proxies for developers guide.
Before You Start
You need a Linux server with root or sudo access, a backend application already running on a local port, and, for HTTPS, a domain name pointed at the server. This Nginx reverse proxy setup uses Ubuntu 24.04 and an app listening on 127.0.0.1:3000, which covers Node, Python, Go, and containerised apps alike. The steps also work on Ubuntu 22.04 and other Debian-based systems, and the configuration syntax is the same on other distributions.
Ubuntu 24.04 ships Nginx 1.24.0 in its own package repository, with security fixes backported rather than new upstream versions, and the Nginx project publishes newer stable releases such as 1.30.8 through its own repository. The examples here use the Ubuntu package, which is the simplest path. Check the version you install with nginx -v, because a few directives changed in recent releases: proxy_http_version 1.1 only became the default in Nginx 1.29.7, so older versions need it set explicitly for WebSocket support.
Step 1: Install Nginx
On Debian and Ubuntu, install Nginx from the default repositories:
sudo apt update
sudo apt install -y nginx
sudo systemctl enable --now nginx
On RHEL-based distributions such as Rocky Linux or AlmaLinux, the equivalent is sudo dnf install nginx followed by the same systemctl enable --now nginx. After installation, open http://your-server-ip in a browser: the default Nginx welcome page confirms the server is running. If the page does not load, check that the firewall allows ports 80 and 443, for example with sudo ufw allow 'Nginx Full' on Ubuntu.
Step 2: Write a Basic Reverse Proxy Configuration
Nginx configuration lives in server blocks. On Ubuntu, each site gets a file in /etc/nginx/sites-available/, which is then linked into /etc/nginx/sites-enabled/. Create a new file for your app rather than editing the default site, so the default stays available as a reference:
sudo nano /etc/nginx/sites-available/app.example.com
Add this minimal Nginx reverse proxy example:
server {
listen 80;
server_name app.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
}
}
The proxy_pass directive is the heart of an Nginx reverse proxy: it tells Nginx where to forward the request. Using Nginx as a forward proxy is a different setup from the reverse proxy in this guide. The location / block matches every path, so all traffic for this domain goes to the app on port 3000. Enable the site and reload Nginx:
sudo ln -s /etc/nginx/sites-available/app.example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Always run nginx -t before reloading. It checks the configuration for syntax errors, and it catches a mistake before it takes down the live site. If the test passes, visit your domain: Nginx forwards the request to the app, and the app’s response comes back through Nginx.
The Trailing Slash Rule in proxy_pass
The trailing slash in proxy_pass changes how Nginx rewrites the request path, and it is the single most common source of broken proxy setups. When proxy_pass has no URI part, Nginx passes the original request URI unchanged. When it has a URI part, even just a slash, Nginx replaces the matched location part with that URI.
# Request: /api/users
# Backend receives: /api/users
location /api/ {
proxy_pass http://backend;
}
# Request: /api/users
# Backend receives: /users
location /api/ {
proxy_pass http://backend/;
}
In the first example, the backend receives the full /api/users path. In the second, the trailing slash strips /api/ and the backend receives /users. Both are correct in different situations: use the first form when the backend expects the full path, and the second when the backend is mounted at the root and should not see the prefix. If your app returns 404s for paths that work when called directly, the trailing slash is the first thing to check. The official NGINX ngx_http_proxy_module documentation describes this rule in full, and it is the reference to trust when a path rewrite behaves unexpectedly.
Forwarding Headers Your App Needs
A backend behind a proxy sees Nginx as the client, not the real visitor, so it loses information unless Nginx forwards it. The standard header set passes the original host, the client IP, and the protocol:
server {
listen 80;
server_name app.example.com;
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 X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
}
Each Nginx proxy_set_header line has a job. Host tells the app which domain the visitor asked for, so apps that serve several domains route correctly. X-Real-IP carries the visitor’s address. X-Forwarded-For carries the chain of addresses a request passed through, with Nginx appending the client address. X-Forwarded-Proto tells the app whether the visitor used HTTP or HTTPS, which matters for redirects and for building absolute URLs. Without these headers, an app may log every visitor as 127.0.0.1, generate http:// links on an HTTPS site, or redirect in a loop.
One warning applies to X-Forwarded-For: an app should only trust the entries added by its own proxy, because a client can send a fake X-Forwarded-For header of its own. If your app uses the header for rate limiting or access control, configure it to trust only the last entries added by Nginx.

Photo via Pexels. Headers carry the client details that the proxy would otherwise hide from your app.
Load Balancing with Upstream Blocks
When one app server is not enough, Nginx can spread requests across several backends with an upstream block. Define the pool once, then point proxy_pass at it:
upstream backend_servers {
server 192.168.1.10:3000;
server 192.168.1.11:3000;
server 192.168.1.12:3000;
}
server {
listen 80;
server_name app.example.com;
location / {
proxy_pass http://backend_servers;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
By default, Nginx uses round-robin balancing, sending each request to the next server in turn. Other methods are available: least_conn sends each request to the server with the fewest active connections, ip_hash sends the same client to the same server every time, and hash routes by a key you choose. Add weight=3 to a server line to give one backend a larger share of traffic, and max_fails=3 fail_timeout=30s to take a failing server out of rotation temporarily.
Load balancing only helps if the app can run on several servers at once. An app that keeps session state in local memory will break when a user lands on a different server on the next request, unless sessions are stored in a shared store or ip_hash keeps each user on one server.

Photo via Pexels. Load balancing only helps if the app can run on several servers at once, so check session storage before adding backends.
WebSocket Support
Nginx reverse proxy WebSocket support needs two extra headers, because the connection starts as an HTTP request and then upgrades to a persistent connection. Without them, Nginx closes the connection after the first exchange:
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
The Upgrade and Connection headers tell Nginx to pass the upgrade through to the backend instead of treating it as a normal request. The long timeouts matter too: a WebSocket connection can sit idle for a long time, and the default proxy timeouts will cut it off. If your app uses WebSockets for chat, live updates, or collaborative editing, these lines belong in every location block that serves them.
Adding HTTPS with Let’s Encrypt
Running a reverse proxy over plain HTTP is fine for a local test and not acceptable for real traffic. This Nginx reverse proxy HTTPS setup uses Certbot with the Nginx plugin, which obtains a certificate from Let’s Encrypt and edits your Nginx configuration for you:
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d app.example.com -d www.app.example.com
Certbot adds a listen 443 ssl block, points it at the certificate files, and adds a redirect from HTTP to HTTPS. Let’s Encrypt’s HTTP-01 challenge needs port 80 open even if you only ever want HTTPS, so keep port 80 reachable. Certificates from Let’s Encrypt are valid for 90 days, and Certbot sets up automatic renewal; verify the renewal works with sudo certbot renew --dry-run. If you manage certificates through a CDN instead, our guide to Cloudflare and CDN proxies explains how the TLS setup changes when a CDN sits in front of Nginx.
Nginx in Docker
Running Nginx in Docker is a common setup, and the Nginx reverse proxy configuration is the same, but the networking changes. Inside a container, 127.0.0.1 means the container itself, not the host, so proxy_pass http://127.0.0.1:3000 will fail unless the app runs in the same container. Point the proxy at the app container by its service name instead:
proxy_pass http://app:3000;
A minimal Docker Compose file for a reverse proxy in front of an app looks like this:
services:
nginx:
image: nginx:latest
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
app:
image: myapp:latest
expose:
- "3000"
The app container only exposes port 3000 to the Docker network, not to the host, so the only way in is through Nginx. That is the point of the setup. For a full Docker-based reverse proxy walkthrough, including volumes and certificate handling, see the Docker section of our Nginx Proxy Manager guide, which runs Nginx behind a web interface instead of hand-written files.

Photo via Pexels. In Docker, the proxy reaches the app by its container name, not by localhost.
Nginx Proxy Manager: The GUI Alternative
Nginx Proxy Manager is the most widely used graphical alternative to hand-written Nginx configuration, and it is also the primary keyword for this guide. The Nginx Proxy Manager Docker image is published as jc21/nginx-proxy-manager on Docker Hub and on GitHub under NginxProxyManager/nginx-proxy-manager. It manages Nginx proxy hosts through a web interface, including free SSL certificates from Let’s Encrypt, without requiring you to write Nginx reverse proxy config files.
The Nginx Proxy Manager Docker Compose file from the project README looks like this:
services:
app:
image: 'docker.io/jc21/nginx-proxy-manager:latest'
restart: unless-stopped
ports:
- '80:80'
- '81:81'
- '443:443'
volumes:
- ./data:/data
- ./letsencrypt:/etc/letsencrypt
Bring the stack up with docker compose up -d, then open the admin interface on port 81. Port 81 is the Nginx Proxy Manager default port for the admin interface, and the Nginx Proxy Manager port mapping in the Compose file is '81:81'. From there you can create forwarding domains, redirections, streams, and 404 hosts, add access lists and basic HTTP authentication, and manage users, permissions, and an audit log. The project reports version 2.17.1 in its README badge and more than 34,000 GitHub stars as of November 2026.
Nginx Proxy Manager suits home servers and small teams that want a reverse proxy without learning Nginx syntax. It is not a replacement for hand-written Nginx when you need custom directives, complex routing, or fine control over caching and buffering: the interface exposes an advanced configuration field for those cases, but the further you go beyond the interface, the more sense it makes to write the config yourself. Our Nginx Proxy Manager guide covers installation on Docker, Unraid, and Proxmox, the default login, Cloudflare setup, and common errors such as bad gateway and forgotten passwords.
If you use Cloudflare in front of Nginx Proxy Manager, set the Cloudflare SSL mode and the proxy headers to match, or you will see redirect loops and mixed-content warnings. The same applies to plain Nginx behind Cloudflare, and it is covered in our Cloudflare and CDN proxies guide.
Other Reverse Proxies Worth Knowing
Nginx is the default choice, but it is not the only one, and the alternatives below each have a guide of their own. Traefik and Caddy are the two modern rivals: Traefik discovers services automatically from Docker labels, and Caddy obtains HTTPS certificates automatically with almost no configuration. Our guide to Traefik and Caddy reverse proxy compares both with Nginx. Apache can do the same job with mod_proxy, and our Apache reverse proxy guide covers it for servers that already run Apache. HAProxy is a dedicated load balancer that also works as a reverse proxy, covered in our HAProxy guide.
Two other tools sit nearby. Envoy is the proxy used in service meshes, where it runs alongside each service and handles routing, retries, and observability between them; see our guide to Envoy and service mesh proxies. Squid is a forward and caching proxy rather than a reverse proxy, but it is often installed on the same servers, and our Squid proxy server guide explains its role. If your network assigns proxies automatically, the mechanism is usually a PAC file or WPAD, covered in our guide to Proxy Auto-Config (PAC) and WPAD.
Finally, a reverse proxy is not the same as an API gateway. An API gateway adds authentication, rate limiting, and request transformation on top of proxying, and it is the right tool when you expose APIs to outside developers. Our guide to API gateway vs reverse proxy explains the difference and when each one fits.

Photo via Pexels. Nginx Proxy Manager gives you the same reverse proxy behind a web interface, with no config files to write.
Troubleshooting: 502, 504, and Other Common Errors
A 502 Bad Gateway means Nginx could not get a valid response from the backend. Check first that the backend is actually running and listening on the port in proxy_pass, with curl http://127.0.0.1:3000 on the server. Check second that the address is right: in Docker, 127.0.0.1 means the Nginx container, not the host. Check third that the backend did not crash on startup, which the app logs will show.
A 504 Gateway Timeout means the backend took too long to answer. The default proxy timeouts are generous for web pages and too short for long-running requests, file uploads, and AI API calls. Raise proxy_read_timeout and proxy_send_timeout for the location that needs it, and check whether the backend itself is slow rather than the proxy.

Photo via Pexels. A 502 means Nginx could not reach the backend at all, while a 504 means the backend took too long to answer. A 413 Request Entity Too Large means the upload exceeded the default client_max_body_size of 1 MB; set it higher in the server block, for example client_max_body_size 25m.
If Nginx serves the default welcome page instead of your app, the server block did not match: check server_name, check that the symlink exists in sites-enabled, and run nginx -t to confirm the file loads. If the site works over HTTP but not HTTPS, check that Certbot added the listen 443 ssl block and that the certificate files exist. If the site redirects in a loop, the app is probably redirecting HTTP to HTTPS while Nginx already terminates TLS, and the fix is to trust X-Forwarded-Proto in the app instead of redirecting again.
Video: Nginx Reverse Proxy with HTTPS in 5 Minutes
The video below puts Nginx in front of an app and adds a free Let’s Encrypt certificate, with every command shown on a real Ubuntu server.
Video: Run Node.js Behind Nginx on Port 80
This short walkthrough rewrites an Nginx config as a reverse proxy for a Node.js app, with one upstream, one proxy_pass, and a check that the app answers through Nginx on port 80.
Frequently Asked Questions
What is an Nginx reverse proxy?
An Nginx reverse proxy is an Nginx server that sits in front of your backend application, receives requests from visitors, forwards them to the app, and returns the response. Visitors only talk to Nginx, and the app stays hidden behind it.
How do I set up Nginx as a reverse proxy?
Install Nginx, create a server block with a location that uses proxy_pass to point at your app, add the standard proxy_set_header lines, run nginx -t, and reload Nginx. Add HTTPS with Certbot afterwards.
What does proxy_pass do in Nginx?
proxy_pass tells Nginx where to forward a request. The address can be a single backend, such as http://127.0.0.1:3000, or an upstream pool of several backends for load balancing.
Why does the trailing slash in proxy_pass matter?
With no URI part, Nginx passes the original request path unchanged. With a trailing slash, Nginx replaces the matched location part with that slash, so /api/users becomes /users at the backend. Pick the form your backend expects.
What is Nginx Proxy Manager?
Nginx Proxy Manager is a Docker container with a web interface for managing Nginx proxy hosts, including free Let’s Encrypt certificates, without writing config files. Its admin interface runs on port 81.
How do I fix a 502 Bad Gateway error in Nginx?
Check that the backend is running and listening on the port in proxy_pass, check that the address is correct for your setup (in Docker, use the container name, not 127.0.0.1), and check the app logs for a startup crash.
Can Nginx handle WebSockets?
Yes, with proxy_http_version 1.1 and the Upgrade and Connection headers set in the location block, plus long proxy_read_timeout and proxy_send_timeout values so idle connections are not cut off.
Is Nginx free?
Yes. Nginx open source is free to install and use, and it is available in the package repositories of most Linux distributions. Commercial support and extra features are available through a paid subscription from F5.
Sources
8
- NGINX. Module ngx_http_proxy_module. https://nginx.org/en/docs/http/ngx_http_proxy_module.html
- NGINX. NGINX Reverse Proxy (admin guide). https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/
- GitHub. NginxProxyManager/nginx-proxy-manager. https://github.com/NginxProxyManager/nginx-proxy-manager
- DigitalOcean. How To Configure Nginx as a Reverse Proxy on Ubuntu. https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-reverse-proxy-on-ubuntu-22-04
- GetPageSpeed. NGINX Reverse Proxy: Setup Guide with proxy_pass Examples (2026). https://www.getpagespeed.com/server-setup/nginx-reverse-proxy
- Ajay Kumar. How to Set Up Nginx as a Reverse Proxy With Let’s Encrypt (Ubuntu 24.04). https://www.ajayk.sh/blog/nginx-reverse-proxy-lets-encrypt-ubuntu-guide/
- Let’s Encrypt. Getting Started. https://letsencrypt.org/getting-started/
- Docker. Docker Compose documentation. https://docs.docker.com/compose/
Every factual claim on this page was verified against a named source above. Nginx versions and Nginx Proxy Manager details were checked on 23 November 2026; check the linked documentation for current details.



