Proxy
A proxy is an intermediary piece of hardware/software that sits between a client (such as a web browser) and the destination server. It intercepts requests from clients and can modify, filter, or forward these requests to the target server, and then relay the response back to the client.
What Is a Proxy?
- Intermediary Role:
A proxy server acts as a middleman between the client and the server. Instead of communicating directly with the destination server, the client sends its requests to the proxy, which then handles the communication with the target server. This setup provides an additional layer between the client and the server. - Communication Handling:
Proxies can manage and inspect traffic, often applying rules such as caching, content filtering, or access control. They can transform requests and responses to meet specific requirements or policies.
Types
There are two types of proxies:
1️⃣ Forward Proxy
A forward proxy, often called a proxy, proxy server, or web proxy is a server that sits in front of a group of client machines. When those computers make requests to sites and services on the internet, the proxy server intercepts those requests and then communicates with web servers on behalf of those clients, like a middleman.
It sits in between the client and the wider network. It is typically used by clients within a private network to access external resources.
Use Cases:
- Access Control: Enforcing policies on what external sites users can access.
- Anonymity: Hiding the client’s IP address when accessing public resources.
- Caching: Storing copies of frequently accessed web pages to improve load times.
2️⃣ Reverse Proxy
A reverse proxy is a server that sits in front of one or more web servers, intercepting requests from clients. When clients send requests to the origin server of a website, those requests are intercepted by the reverse proxy server.
The difference between a forward and reverse proxy is subtle but important. A simplified way to sum it up would be to say that a forward proxy sits in front of a client and ensures that no origin server ever communicates directly with that specific client. On the other hand, a reverse proxy sits in front of an origin server and ensures that no client ever communicates directly with that origin server.
It sits in front of one or more web servers. It receives requests from the internet and forwards them to the appropriate backend server.
Use Cases:
- Load Balancing: Distributing incoming traffic across multiple servers.
- Security: Protecting backend servers from direct exposure and attacks.
- SSL Termination: Offloading encryption/decryption tasks from the backend servers.
- Caching: Serving cached content to reduce server load and improve response times.
Note:
Isn't the reverse proxy similar to a load balance?
Both load balancers and reverse proxies act as intermediaries between clients and servers, but they serve slightly different purposes:
- Load Balancer:
Its main function is to distribute incoming traffic across multiple backend servers that serve the same purpose. This ensures high availability and scalability by preventing any single server from becoming overloaded. Load balancers use various algorithms (such as round robin, least connections, etc.) to decide how to route requests among a group of servers. - Reverse Proxy:
A reverse proxy also sits between the client and the server, but it can provide a broader set of functionalities. It can be used with a single server to improve security, perform SSL termination, cache content, and compress data, in addition to possibly balancing load. When deployed in front of multiple servers, a reverse proxy can also perform load balancing tasks.- A reverse proxy can also act as a load balancer but not the vice verse.