A reverse proxy is a server that sits between your users and your web applications: it receives the requests on ports 80 and 443, forwards them to the right internal service, and sends the response back. The visitor only sees the proxy, not the applications running behind it. The best-known reverse proxy is Nginx, but Nginx Proxy Manager, which you manage through a web interface, and Traefik, which was designed for containers, are also increasingly popular.
A “plain” proxy (forward proxy) is the opposite: it goes out to the internet on behalf of internal users, for example as a company web filter. A reverse proxy receives incoming traffic on behalf of the servers.
What is a reverse proxy good for?
- Several services on one IP address. One server can run the website, an internal wiki and a monitoring interface; the proxy decides from the domain name which one the request goes to.
- TLS in one place. The proxy manages and renews the HTTPS certificates, so the internal applications don’t have to deal with them (TLS termination).
- Load balancing. It can spread requests across several identical application instances, and take any instance that isn’t responding out of rotation.
- Security. The applications can’t be reached directly from the internet, and security headers, request size limits and rate limiting can be set up in one place on the proxy.
- Caching and compression. The proxy can serve static content itself, taking the load off the application.
Nginx as a reverse proxy
Nginx is the most widespread choice: it’s fast, uses little memory, is included in every distribution, and its configuration lives in text files, so it can be version-controlled. Currently 1.26 is the stable branch and 1.27 the development (mainline) branch. Forwarding to an internal application on port 3000:
server {
listen 80;
server_name app.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
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;
}
}
From the X-Forwarded-* headers, the application learns the visitor’s real IP address and whether the request arrived over HTTPS. For applications that use WebSocket (chat, live notifications), you also need the proxy_http_version 1.1; line and to forward the Upgrade and Connection headers.
Certbot requests the Let’s Encrypt certificate and also writes it into the configuration:
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d app.example.com
For load balancing, list the application instances in an upstream block and point proxy_pass at that name. By default, Nginx spreads the requests in round-robin fashion, and if an instance doesn’t respond, it skips it for a while:
upstream app_backend {
server 10.0.0.11:3000;
server 10.0.0.12:3000;
}
When is it a good fit? When you have to serve a few services that rarely change, when full control matters, and when you manage the configuration in Git or with Ansible.
Nginx Proxy Manager: Nginx with a web interface
Nginx Proxy Manager (NPM) is a Docker container that runs Nginx and adds a web interface to it: you can set up forwarding, Let’s Encrypt certificates, redirects and simple access restrictions with a few clicks. Its latest release is 2.12.3, from February. The minimal docker-compose.yml according to the project’s documentation:
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
After docker compose up -d, the interface is available on port 81. If you don’t have Docker on your server yet, we have described how to install it step by step in the knowledge base of aWh, our hosting brand. Change the default login details (admin@example.com / changeme) immediately at the first login, and never expose port 81 to the internet: restrict it to your own IP address with a firewall, or only use it over a VPN.
When is it a good fit? In a home lab, in a smaller office, or if the forwarding rules are also managed by a colleague who doesn’t want to edit configuration files. Its drawback is that the settings live in a database, they are harder to version-control and automate, and special Nginx settings have to be typed into a text field.
Traefik: designed for containers
Traefik (version 3.3 was released in January) works on a different principle: you don’t have to list the forwarding rules yourself; it reads from the Docker containers’ labels which container belongs to which domain. If you start a new container with the right labels, Traefik forwards traffic to it within seconds, and requests a certificate for it too.
services:
traefik:
image: traefik:v3.3
command:
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --entrypoints.web.address=:80
- --entrypoints.websecure.address=:443
- --certificatesresolvers.le.acme.email=admin@example.com
- --certificatesresolvers.le.acme.storage=/letsencrypt/acme.json
- --certificatesresolvers.le.acme.httpchallenge.entrypoint=web
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./letsencrypt:/letsencrypt
app:
image: traefik/whoami
labels:
- traefik.enable=true
- traefik.http.routers.app.rule=Host(`app.example.com`)
- traefik.http.routers.app.entrypoints=websecure
- traefik.http.routers.app.tls.certresolver=le
When is it a good fit? If you have many containers and services come and go often, or if you use Docker Swarm or Kubernetes. Keep in mind that Traefik reads the containers through the Docker socket; whoever takes over the Traefik container can take over the Docker host too. In production it’s therefore worth putting a socket proxy in between, or using file-based configuration.
Comparison
| Nginx | Nginx Proxy Manager | Traefik | |
|---|---|---|---|
| Management | Configuration file | Web interface | Container labels, file |
| Certificates | Certbot separately | Built-in Let’s Encrypt | Built-in ACME |
| Version-controllable | Yes | With difficulty | Yes |
| Docker required | No | Yes | In practice, yes |
| Learning curve | Medium | Low | Medium |
| Best for | Stable, few services | Small environment, point-and-click management | Many changing containers |
A few basic security rules
- From the outside, only ports 80 and 443 should be open, and everything else should be closed; the aWh knowledge base helps with setting up the firewall.
- Internal applications should only listen on
127.0.0.1or on an internal Docker network, so that the proxy can’t be bypassed. - The application should only accept the real client IP from the headers when they come from the proxy, and from nowhere else.
- Update the proxy and the containers regularly, because this is the most exposed point facing the internet.
There is always DNS in front of a reverse proxy: the domain names have to point to the proxy’s IP address. We wrote about how DNS works in the aWh knowledge base. We help with designing and running web services, container environments and the reverse proxy that goes with them; you can read about this on the Cloud and DevOps page.