Reverse Proxy: How It Works, Examples, and Use Cases

8 de Octubre de 2024
por Sagar Joshi

In networking, a proxy acts as a middleman between the client and the server, managing requests and responses on behalf of the other devices. 

Reverse proxies, however, lie in front of web servers. They forward client requests to the server and return the server’s response back to the clients. From the client’s perspective, it appears as though the response is originating from the original web server when it’s actually coming from the reverse proxy server. 

Reverse proxy offers a layer between the client and the server, providing additional control to ensure the network traffic flows seamlessly. Many organizations use it with load balancing software to distribute high-traffic while maintaining proper website functionalities. 

The reverse proxy layer in front of the web server scans the client’s request for malicious activity before the traffic lands on your web server.

How does a reverse proxy work?

Reverse proxies have one purpose: to shield web servers from incoming traffic. They receive connection requests, send them to different servers, and then establish a connection with the server processing the request. 

Below are three stages in which reverse proxies operate. 

  • Request collection: The reverse proxy intercepts incoming requests coming from clients. 
  • Transmission control protocol (TCP) three-way handshake: A connection is established with the reverse proxy, which terminates the initial connection and initiates a new connection with the server. 
  • Origin server connection: The client request is forwarded to the server using a decoy IP address to mask the origin server.

Most web applications use a reverse proxy to handle requests from a web browser. They don’t allow clients to connect directly with an origin server. This protects sensitive data and minimizes the risk of unauthorized access. 

The reverse proxy also examines servers' responses for anything a malicious hacker can use to gain unauthorized access to internal resources.

Here’s how reverse proxy works in Internet communication. 

Here’s how reverse proxy works in Internet communication:

  • Internet: Where can I find “media.example.com”?
  • DNS: It’s at this internet protocol (IP) address X.XX.XXX.X. It’s your router’s public IP address.
  • Internet: Router, where is media.example.com?
  • Router: This is a request from port 80/443. I forward all requests on those ports to 192.168.1.10.
  • Internet: Hi 192.168.1.10 on port 80/443, where’s media.example.com?
  • Reverse proxy: It’s right here on port 8080. I’ll forward it to you on port 80/443. 

¿Quieres aprender más sobre Software de Balanceo de Carga? Explora los productos de Balanceo de carga.

What do reverse proxy servers do?

Reverse proxy servers take care of multiple things when seeking online information. These servers can: 

  • Conceal an origin server’s characteristics and existence.
  • Carry out transport layer security (TLS) acceleration hardware to perform TLS encryption in place of secure websites. 
  • Balance loads of incoming requests among servers, supporting their application areas. 
  • Reduce load on the origin server by working as a web acceleration server that can cache static and dynamic content. 
  • Conduct multivariate and A/B testing without inserting JavaScript directly into the pages. 
  • Free up server resources during transfer time by serving clients dynamically generated pages bit by bit, even when they’re produced at once. 
  • Deliver incoming requests to multiple web servers within a local area network while assessing them via a single public IP address.

Why do you need a reverse proxy server?

Reverse proxies facilitate load balancing for application programming interfaces (APIs) and web applications. You can easily offload services from applications, improving performance through SSL acceleration, compression, and caching. It offers an additional layer of abstraction with the following.

Increased security, scalability, and flexibility

Your backend server information is hidden from all clients, preventing hackers from accessing it or exploiting vulnerabilities. Reverse proxies also help prevent the origin server from distributed denial-of-service (DDoS) attacks by rejecting traffic from certain IP addresses or limiting clients’ connection requests. 

Since the origin server is not directly exposed, you can easily change the backend’s configuration. This is useful for load-balanced environments, where you can match traffic volume fluctuations by scaling the number of servers up or down. 

With a reverse proxy, you never need to reveal the IP address of your origin server. All requests go to the reverse proxy, such as Cloudflare’s content delivery network (CDN), which will have more robust security and extensive resources to protect against cyber attacks. 

Compression at the proxy level

Reverse proxies reduce the amount of data needed to be shared with the network. Many proxy servers use Gzip compression on hypertext markup language (HTML), cascading style sheets (CSS), JavaScript Object Notation (JSON), JavaScript, Extensible Markup Language (XML), and various other content types. 

Balancing the load

Managing millions of users daily on a website with a single origin server becomes tricky. Usually, such sites use a distributed pool of servers, handling all requests at the same time. Reverse proxy and load balancing software offer a solution in such cases by distributing incoming requests among different servers and minimizing overload. In cases of server failure, the load is managed by other servers in the pool.

For global applications, reverse proxies can route client requests to the server closest to them to reduce latency and speed up response times. This geographical distribution is a key benefit for large-scale websites with global traffic.

Caching

A reverse proxy server caches content to improve performance. For example, if a person in India visits a reverse-proxied website with servers in Los Angeles, they might connect to a local reverse proxy in India. The proxy would communicate with the server in Los Angeles. 

The local reverse proxy server in India caches the response data. The next time someone from India attempts to visit the website, the local reverse proxy shows them the cached version of the website, making its performance faster. 

Encryption

Applying secure socket layer (SSL) encryption or decryption can be computationally expensive to run on the origin server. In such cases, organizations uses a reverse proxy to decrypt all incoming requests and encrypt outgoing responses. 

It frees up valuable resources on the origin server, making it more effective in running critical operations. 

Reverse proxy vs. forward proxy

A reverse proxy sits in front of the server, managing incoming requests from the client. On the other hand, a forward proxy (commonly called a proxy) sits in front of client machines. When these machines communicate with the Internet and send requests, the proxy server interprets them and communicates with the web server on behalf of the clients. 

To understand a typical forward proxy communication in detail, let’s take an example: 

Consider three home computers {A}, a forward proxy server {B}, and a website’s origin server {C}.

forward proxy flow

Source: Cloudflare

Without a proxy server, a computer A would connect directly with the server C to send the request and get responses from the server. With a forward proxy, A sends requests to B, which forwards them to C. The response follows the same path, keeping the client (A) anonymous. 

Conversely, reverse proxies intercept client requests at the network edge in front of a website's origin server. 

The difference between a forward and a reverse proxy is subtle. While a reverse proxy ensures that no client communicates directly with the origin server, a forward proxy ensures that no origin server ever communicates directly with the specific client. 

Below are a few notable differences between reverse proxy and forward proxy. 

  • Usage: Forward proxies help monitor and control the web content that employees access and prevent malicious traffic from reaching origin servers. They use cache content for web acceleration, improving the load time and users’ experience. 
  • Direction of traffic: In the case of reverse proxy, the direction of traffic flow is inbound (internet to the server). For forward proxy, it’s from client to server. 
  • Caching: Reverse proxy caches static content for load balancing. Forward proxies cache frequently accessed content. 
  • SSL/TLS handling: Reverse proxies terminate SSL/TLS connections for servers, while forward proxies initiate these connections on behalf of clients. 
  • Scalability: Reverse proxies scale with the number of servers. Forward proxies scale with the number of clients. 

Common use cases of reverse proxies

Below are some common use cases of reverse proxies in an organization. 

  • Serving static content: A website has a mixture of dynamic and static content. Some organizations configure their reverse proxy server to serve static content, reducing the load time and freeing up more power for dynamic content rendering. 
  • Preventing data breaches: Reverse proxies encrypt the data transmitted through a network, helping businesses protect against data breaches
  • Routing client requests based on geolocation: A reverse proxy can route clients' requests to the server that is closer to them based on their geographic location. 
  • Securing web gateways: Reverse proxies hide the identity of the origin server, keeping it safe from threat actors. 

Apart from these, reverse proxies are used in content delivery networks to cache content at network edges closer to the client and in mobile web services to optimize images and scripts for mobile devices. 

Manage high-traffic flow efficiently

Overall, reverse proxies are versatile tools with applications in multiple use cases. For any business struggling with managing heavy traffic, reverse proxy offers a solution to make the traffic flow seamlessly. It improves server efficiency and adds an additional layer of security, ensuring web traffic and hackers are kept outside your networks. 

Choose the right reverse proxy and load balancer for your business and keep your website up and running efficiently. 

Learn more about how a load balancer distributes high incoming traffic on an application while ensuring proper functionality. 

Edited by Monishka Agrawal

Sagar Joshi
SJ

Sagar Joshi

Sagar Joshi is a former content marketing specialist at G2 in India. He is an engineer with a keen interest in data analytics and cybersecurity. He writes about topics related to them. You can find him reading books, learning a new language, or playing pool in his free time.