TL;DR
|
A reverse proxy is a server that stands between visitors and your app. Every request from a browser reaches the reverse proxy first, which decides where it should go, passes it to the app, and sends the answer back.
From the visitor's side, the reverse proxy is the website. The app servers behind it never talk to the internet directly. This guide explains what reverse proxies do, how they differ from forward proxies and load balancers, and which tools fill the role.
Key takeaway: the reverse proxy is the front door. It receives each request, forwards it to the right app, and returns the response.
A request to a site behind a reverse proxy goes through four steps:
Because every request passes through it, the reverse proxy is a natural place for jobs that apply to the whole site. When it can't get a good answer from the app, it's also the server that reports an error such as a 502 or 504. Our guide 502 Bad Gateway: what it means and how to fix it explains those errors.
Key takeaway: a reverse proxy handles shared jobs once, in front of every app, so the apps don't have to.
| Job | What it means |
|---|---|
| Routing | Sends example.com to one app and example.com/api to another, or different domains to different apps |
| HTTPS | Handles the secure connection and its certificate, so apps don't each need one |
| Load balancing | Spreads requests across several copies of an app |
| Caching | Keeps copies of responses and serves repeat requests without bothering the app |
| Compression | Shrinks responses before sending them, so pages load faster |
| Security | Hides the apps' real addresses, and can block unwanted traffic or limit how often someone can make requests |
| Redirects and rewrites | Moves visitors from old addresses to new ones |
Key takeaway: a forward proxy works for the people browsing. A reverse proxy works for the website.
| Forward proxy | Reverse proxy | |
|---|---|---|
| Sits in front of | Users | Servers |
| Acts on behalf of | The people making requests | The website receiving them |
| Who knows it's there | The users, who are set up to use it | Usually nobody. Visitors think they're talking to the website |
| Typical uses | Filtering web access at a company or school, hiding a user's location | Routing, HTTPS, caching, and load balancing for a website |
Key takeaway: load balancing is one of the jobs a reverse proxy can do. A load balancer is a tool that specializes in that job.
The two terms overlap a lot. A load balancer spreads traffic across several servers. A reverse proxy can do that, plus HTTPS, caching, routing, and more. Many tools do both: Nginx and HAProxy are often described as either one, depending on how they're used. Our guide What is a load balancer? covers load balancing in detail.
Key takeaway: the same tools show up again and again, from a single server to a global network.
| Tool | Notes |
|---|---|
| Nginx | A web server that's often set up as a reverse proxy |
| HAProxy | Focused on load balancing and proxying, known for high performance |
| Caddy | Gets HTTPS certificates automatically with little setup |
| Traefik | Popular with containers, because it can configure itself as apps start and stop |
| Apache HTTP Server | Can act as a reverse proxy with its proxy modules |
| CDNs such as Cloudflare or Fastly | Reverse proxies spread across many locations worldwide, so responses come from somewhere close to the visitor |
Key takeaway: many reverse proxy problems come from the app not knowing it's behind one.
| Mistake | What happens | How to avoid it |
|---|---|---|
| The app logs the proxy's address instead of the visitor's | Logs, rate limits, and location features all see the same address | Read the visitor's real address from the header the proxy adds |
| The app thinks every request is insecure | Because the proxy handles HTTPS, the app sees plain connections and may redirect in a loop | Tell the app it's behind a proxy, so it trusts the proxy's information about the original connection |
| Time limits that don't match | The proxy gives up before a slow request finishes, showing visitors a 504 | Keep slow work out of web requests, or align the time limits |
| Caching private pages | One user's page is shown to another | Make sure pages with personal data aren't cached |
Key takeaway: on Upsun Cloud, a router sits in front of your apps and does the reverse proxy's job, configured in the same file as the rest of your project.
On Upsun Cloud, every request passes through a router before it reaches your app. Its behavior is set in the routes section of .upsun/config.yaml, alongside your apps and services. Here's what it does, according to the Upsun docs:
| Reverse proxy job | How the Upsun Cloud router handles it |
|---|---|
| Routing | Routes in .upsun/config.yaml decide which app receives each domain and path |
| HTTPS | Certificates are provided automatically through Let's Encrypt, including for preview environments |
| Load balancing | When an app runs as several instances, the router spreads requests across the available instances |
| Caching | A router cache can serve repeat requests, following the cache headers your app sends |
| Redirects | Whole-route and path-level redirects are set in routes |
| The visitor's real address | The router passes it to your app in the X-Client-IP header |
You can also add a Varnish service between the router and your apps if you need more control over caching. For how requests reach the router in the first place, read Life on the edge: understanding the Upsun edge layer.
You can deploy on Upsun Cloud free for 15 days, with no card needed, or read the routes documentation to see every option.
A server that stands in front of a website's apps, receives every visitor's request, passes it to the right app, and returns the answer.
Nginx is a web server that's very often used as a reverse proxy. The same software can serve files, act as a reverse proxy, and balance load.
Yes. A CDN is a network of reverse proxies in many locations, which cache and serve responses close to visitors.
A regular, or forward, proxy acts for users and sends their requests out to websites. A reverse proxy acts for a website and receives requests from users.
For anything beyond a simple single-server site, usually yes, because it handles HTTPS, routing, and caching in one place. Many hosting platforms include one, so you may already have one without setting it up.