• Docs
  • Talk to an expert
Blog
Blog
BlogProductCase studiesNewsInsights
Blog

What is a reverse proxy?

infrastructureNGINXperformance
Share

TL;DR

  • A reverse proxy is a server that sits in front of one or more apps, receives every request first, and passes it on to the right app.
  • Visitors only ever talk to the reverse proxy. The apps behind it stay hidden.
  • Common jobs include handling HTTPS, spreading traffic across servers, caching responses, compressing data, and blocking unwanted requests.
  • A forward proxy works the other way around: it sits in front of users and makes requests on their behalf.
  • Nginx, HAProxy, Caddy, Traefik, and Apache are common reverse proxy tools, and CDNs act as reverse proxies at a global scale.
  • On Upsun Cloud, a router in front of your apps does this job: it routes requests, provides HTTPS certificates, caches responses, and spreads traffic across instances.

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.

How a reverse proxy works

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:

  1. A visitor's browser sends a request to the website's address.
  2. The reverse proxy receives it, because that address points to the proxy.
  3. The proxy decides which app should handle it, based on rules such as the domain or the path, and forwards the request.
  4. The app answers, and the proxy passes the response back to the browser.

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.

What a reverse proxy is used for

Key takeaway: a reverse proxy handles shared jobs once, in front of every app, so the apps don't have to.

JobWhat it means
RoutingSends example.com to one app and example.com/api to another, or different domains to different apps
HTTPSHandles the secure connection and its certificate, so apps don't each need one
Load balancingSpreads requests across several copies of an app
CachingKeeps copies of responses and serves repeat requests without bothering the app
CompressionShrinks responses before sending them, so pages load faster
SecurityHides the apps' real addresses, and can block unwanted traffic or limit how often someone can make requests
Redirects and rewritesMoves visitors from old addresses to new ones

Reverse proxy vs forward proxy

Key takeaway: a forward proxy works for the people browsing. A reverse proxy works for the website.

Forward proxyReverse proxy
Sits in front ofUsersServers
Acts on behalf ofThe people making requestsThe website receiving them
Who knows it's thereThe users, who are set up to use itUsually nobody. Visitors think they're talking to the website
Typical usesFiltering web access at a company or school, hiding a user's locationRouting, HTTPS, caching, and load balancing for a website

Reverse proxy vs load balancer

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.

Common reverse proxy tools

Key takeaway: the same tools show up again and again, from a single server to a global network.

ToolNotes
NginxA web server that's often set up as a reverse proxy
HAProxyFocused on load balancing and proxying, known for high performance
CaddyGets HTTPS certificates automatically with little setup
TraefikPopular with containers, because it can configure itself as apps start and stop
Apache HTTP ServerCan act as a reverse proxy with its proxy modules
CDNs such as Cloudflare or FastlyReverse proxies spread across many locations worldwide, so responses come from somewhere close to the visitor

Common reverse proxy mistakes

Key takeaway: many reverse proxy problems come from the app not knowing it's behind one.

MistakeWhat happensHow to avoid it
The app logs the proxy's address instead of the visitor'sLogs, rate limits, and location features all see the same addressRead the visitor's real address from the header the proxy adds
The app thinks every request is insecureBecause the proxy handles HTTPS, the app sees plain connections and may redirect in a loopTell the app it's behind a proxy, so it trusts the proxy's information about the original connection
Time limits that don't matchThe proxy gives up before a slow request finishes, showing visitors a 504Keep slow work out of web requests, or align the time limits
Caching private pagesOne user's page is shown to anotherMake sure pages with personal data aren't cached

The reverse proxy on Upsun Cloud

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 jobHow the Upsun Cloud router handles it
RoutingRoutes in .upsun/config.yaml decide which app receives each domain and path
HTTPSCertificates are provided automatically through Let's Encrypt, including for preview environments
Load balancingWhen an app runs as several instances, the router spreads requests across the available instances
CachingA router cache can serve repeat requests, following the cache headers your app sends
RedirectsWhole-route and path-level redirects are set in routes
The visitor's real addressThe 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.

Frequently asked questions

What is a reverse proxy in simple terms?

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.

Is Nginx a reverse proxy?

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.

Is a CDN a reverse proxy?

Yes. A CDN is a network of reverse proxies in many locations, which cache and serve responses close to visitors.

What is the difference between a proxy and a reverse proxy?

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.

Do I need a reverse proxy?

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.

Stay updated

Subscribe to our monthly newsletter for the latest updates and news.

Deploy possibility.
Try Upsun for free.

Build with DispatchDeploy on Cloud