
When you visit a website, your browser sends a request to a server, and the server returns the requested page or data. This process sounds simple, but modern applications often have multiple servers, APIs, databases, and services working together behind the scenes.
So, how do websites manage incoming traffic, protect their backend servers, distribute requests, and improve performance?
One important technology that helps solve these challenges is a reverse proxy.
A reverse proxy sits between clients and backend servers. It receives incoming requests, forwards them to the appropriate server when necessary, and returns the responses to clients. It can also provide additional capabilities such as load balancing, caching, TLS termination, and access control.
Reverse proxies are widely used in modern web applications, cloud infrastructure, microservices, and production environments.
In this guide, you'll learn:
What a reverse proxy is.
How a reverse proxy works.
The difference between a reverse proxy and a forward proxy.
Why developers use reverse proxies.
How to configure NGINX as a reverse proxy.
How reverse proxies work with Node.js applications.
Common mistakes and best practices.
Let's get started!
What Is a Reverse Proxy?
A reverse proxy is a server or software component that receives requests from clients and forwards them to one or more backend servers.
Instead of connecting directly to the application server, the client communicates with the reverse proxy. The proxy decides how to handle the request and returns the appropriate response.
For example, imagine you're building a web application with the following components:
A frontend application.
A Node.js backend API.
An authentication service.
A database.
An image or file storage service.
You could expose individual application services directly to users, but doing so can make your architecture harder to manage.
A reverse proxy provides a single entry point for incoming traffic and routes requests to the appropriate backend service.
Simple Example
Imagine your application is available at:
https://www.example.com
Behind this domain, your infrastructure might contain:
Frontend server:
localhost:3000Backend API:
localhost:5000Authentication service:
localhost:6000
A reverse proxy could route requests like this:
Incoming Request | Destination |
|---|---|
| Frontend server |
| Backend API |
| Backend API |
| Authentication service |
Visitors use the same public domain without needing to know which internal service handles each request.
This approach simplifies routing and allows the backend infrastructure to change without requiring users to know its internal details.
How Does a Reverse Proxy Work?
A reverse proxy typically sits between users and the application's backend servers.
Here's the basic request flow:
Client → Reverse Proxy → Backend Server → Reverse Proxy → Client
Let's understand the process step by step.
Step 1: The Client Sends a Request
A user opens a website or sends an API request.
For example:
GET /api/users HTTP/1.1
Host: www.example.comThe browser sends the request to the public endpoint for www.example.com.
Step 2: The Reverse Proxy Receives the Request
The reverse proxy listens for incoming connections, usually on ports 80 for HTTP and 443 for HTTPS.
It can inspect information such as:
The requested domain.
The URL path.
HTTP headers.
The request method.
Routing and access-control rules.
The proxy uses its configuration to determine how the request should be handled.
Step 3: The Reverse Proxy Selects a Backend
The proxy forwards the request to the appropriate backend service.
For example:
/api/users → Node.js API on port 5000If multiple backend servers are available, the reverse proxy may choose one according to a load-balancing strategy.
Step 4: The Backend Processes the Request
The backend application receives the request, executes its business logic, and retrieves or updates data if necessary.
For example, a Node.js API might query a PostgreSQL database to retrieve a list of users.
The backend then generates an HTTP response.
Step 5: The Reverse Proxy Returns the Response
The backend sends its response to the reverse proxy, which forwards it to the client.
The browser receives the response as if it came from the public website.
The client generally does not need to know the internal address of the backend server.
Example Architecture
Internet
|
v
+-------------+
| Client |
| Browser |
+-------------+
|
| HTTPS Request
v
+--------------------+
| Reverse Proxy |
| NGINX |
+--------------------+
|
+---------+----------+
| | |
v v v
+---------+ +---------+ +----------+
| Frontend| | Node.js | | Auth API |
| :3000 | | API:5000| | :6000 |
+---------+ +---------+ +----------+
|
v
+-------------+
| Database |
+-------------+This architecture allows the reverse proxy to manage incoming traffic while the backend services focus on their specific responsibilities.
Reverse Proxy vs Forward Proxy
A reverse proxy and a forward proxy both act as intermediaries, but they serve different purposes.
The main difference is which side of the communication they sit in front of.
What Is a Forward Proxy?
A forward proxy sits between clients and the internet.
For example, a company might configure a forward proxy to control which external websites employees can access.
The employee's device sends a request to the proxy, which forwards it to the destination website according to the configured policies.
Forward proxies are commonly used for:
Controlling outbound internet access.
Filtering web traffic.
Monitoring network activity.
Applying organizational access policies.
Providing certain privacy or anonymity features.
What Is a Reverse Proxy?
A reverse proxy sits between external clients and backend servers.
It manages incoming traffic to an application and forwards requests to the appropriate services.
Common uses include:
Load balancing.
Backend routing.
TLS termination.
Caching.
Access control.
Protecting backend infrastructure.
Comparison Table
Feature | Forward Proxy | Reverse Proxy |
|---|---|---|
Sits in front of | Clients | Servers |
Main purpose | Manage outgoing requests | Manage incoming requests |
Common users | Organizations and client devices | Websites and application infrastructure |
Typical use | Web filtering and outbound access control | Load balancing and backend routing |
Hides | Client network details from destination servers in some configurations | Backend server details from clients |
Example | Corporate web proxy | NGINX or HAProxy in front of an application |
Both can improve control over network communication, but they solve different architectural problems.
Why Do Developers Use a Reverse Proxy?
Reverse proxies offer several benefits that make them valuable for production applications.
Let's explore the most important ones.
1. Load Balancing
Load balancing distributes incoming requests across multiple backend servers.
Imagine an application receives thousands of requests every second. A single server might struggle to handle that traffic.
Instead of sending every request to one server, a reverse proxy can distribute requests across several instances.
For example:
Incoming Traffic
|
v
+-------------+
| NGINX Proxy |
+-------------+
/ | \
/ | \
v v v
Server 1 Server 2 Server 3Each server handles a portion of the incoming workload.
Benefits include:
Better use of available server resources.
Increased capacity.
Reduced pressure on individual instances.
Potentially improved availability when a backend server fails.
Load balancing does not automatically guarantee high availability. Health checks, appropriate failure handling, capacity planning, and redundancy are also important.
2. Improved Security
A reverse proxy creates an additional layer between the public internet and backend infrastructure.
Instead of exposing every backend service directly, you can expose the reverse proxy and restrict direct access to internal services.
This can help:
Reduce the number of publicly accessible services.
Enforce access-control policies.
Integrate a web application firewall.
Apply request limits.
Filter certain unwanted traffic.
Hide internal network addresses from ordinary client-facing responses.
However, a reverse proxy does not automatically make an application secure.
If backend ports remain publicly accessible, attackers may bypass the proxy entirely. Backend services should be protected with appropriate network rules, authentication, and authorization.
3. SSL/TLS Termination
Modern websites use HTTPS to encrypt communication between clients and servers.
A reverse proxy can terminate incoming TLS connections, meaning it handles the client's encrypted connection and then forwards the request to a backend service.
For example:
Browser
|
| HTTPS
v
Reverse Proxy
|
| HTTP or HTTPS
v
Backend ApplicationThe connection between the reverse proxy and the backend may use HTTP or HTTPS, depending on the security requirements and network environment.
If the backend connection crosses an untrusted network, use encryption and appropriate certificate validation.
TLS termination can simplify certificate management because certificates for public-facing domains can be managed at the proxy layer.
4. Caching
Caching allows frequently requested content to be stored temporarily so that it can be served without contacting the backend every time.
For example, suppose a blog article receives thousands of visits per day.
If the article's content changes infrequently, a reverse proxy or caching layer may store the response and serve subsequent requests from the cache.
This can reduce:
Backend processing.
Database queries.
Response latency.
Infrastructure costs.
Caching works especially well for suitable static assets and public content.
However, developers must configure caching carefully. User-specific responses, private account data, and sensitive API responses should not be cached publicly.
5. Centralized Routing
A reverse proxy can route requests to different services based on the domain, URL path, or other configured properties.
For example:
example.com/ → Frontend application
example.com/api/ → Backend API
example.com/auth/ → Authentication service
example.com/uploads/ → File serviceThis lets multiple services operate behind a single public domain.
It can also simplify frontend development by allowing the frontend to call /api/users rather than using a different public hostname for every backend service.
6. Compression and Response Optimization
A reverse proxy can compress eligible HTTP responses before sending them to clients.
For example, text-based resources such as HTML, CSS, JavaScript, and JSON can often be compressed effectively.
Smaller responses can reduce bandwidth usage and improve transfer times, especially for users on slower connections.
Compression settings should be chosen carefully. Already-compressed formats such as JPEG images and many video formats typically gain little from additional compression.
7. Better Application Reliability
Reverse proxies can support reliability by distributing traffic, applying timeouts, and working with multiple backend instances.
For example, if one application instance becomes unavailable, a properly configured load balancer may route new requests to healthy instances.
This can reduce the impact of individual server failures.
However, the proxy itself can become a single point of failure if it has no redundancy. Production systems often use multiple proxy instances or a managed proxy service.
What Is NGINX, and Why Is It Used as a Reverse Proxy?
NGINX is a web server that can also function as a reverse proxy, load balancer, and HTTP cache.
Developers commonly use NGINX in front of Node.js applications, Python services, PHP applications, and other backend systems.
For example, a Node.js application might run on port 3000 while NGINX listens on ports 80 and 443.
Instead of exposing the Node.js port directly to users, NGINX forwards incoming requests to the application.
This setup can help developers manage public traffic, TLS configuration, request routing, and selected performance features in one place.
How to Configure NGINX as a Reverse Proxy
Let's create a simple reverse proxy configuration.
Suppose your Node.js application runs locally on port 3000.
You can access the application directly at:
http://127.0.0.1:3000Now you want NGINX to receive public requests and forward them to that application.
Step 1: Install NGINX
On Ubuntu or Debian-based systems, run:
sudo apt update
sudo apt install nginxCheck whether NGINX is running:
sudo systemctl status nginxIf needed, start it:
sudo systemctl start nginxThe exact installation and service commands may differ depending on your operating system or hosting environment.
Step 2: Start Your Node.js Application
Create a basic Express application.
First, create a project:
mkdir reverse-proxy-demo
cd reverse-proxy-demo
npm init -y
npm install expressCreate an app.js file:
const express = require("express");
const app = express();
const PORT = 3000;
app.get("/", (req, res) => {
res.send("Hello from the Node.js application!");
});
app.get("/api/users", (req, res) => {
res.json([
{ id: 1, name: "Aman" },
{ id: 2, name: "Priya" }
]);
});
app.listen(PORT, "127.0.0.1", () => {
console.log(`Server running on port ${PORT}`);
});Run the application:
node app.jsThe application now listens on the loopback interface at port 3000, making it accessible locally on the same machine.
Step 3: Configure NGINX
Create a server configuration for your application.
On a typical Ubuntu installation, you can create a file such as:
sudo nano /etc/nginx/sites-available/reverse-proxy-demoAdd the following configuration:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
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;
}
}Replace example.com with your actual domain name.
This configuration tells NGINX to forward requests received by this server to the Node.js application.
The headers provide information about the original request. Your application must be configured to trust forwarded headers only when they come from trusted proxies.
For example, X-Forwarded-For should not be blindly trusted when clients can send their own values directly.
Step 4: Enable the Configuration
On Ubuntu installations that use sites-available and sites-enabled, enable the configuration with:
sudo ln -s \
/etc/nginx/sites-available/reverse-proxy-demo \
/etc/nginx/sites-enabled/Test the configuration:
sudo nginx -tIf the test succeeds, reload NGINX:
sudo systemctl reload nginxStep 5: Test the Reverse Proxy
If your domain points to the server and the required network rules are configured, open:
http://example.comNGINX should forward the request to the Node.js application and return:
Hello from the Node.js application!You can also test the API endpoint:
http://example.com/api/usersThe response should contain JSON:
[
{
"id": 1,
"name": "Aman"
},
{
"id": 2,
"name": "Priya"
}
]You now have a basic NGINX reverse proxy in front of a Node.js application.
Important: This example demonstrates HTTP proxying. For a production deployment, configure HTTPS, restrict access to the backend port, review firewall rules, and configure timeouts and logging according to your application requirements.
Reverse Proxy vs Load Balancer
These terms are closely related, but they are not identical.
A reverse proxy receives and forwards requests between clients and backend servers. A load balancer distributes traffic across multiple backend instances.
A reverse proxy can perform load balancing, but it does not have to.
For example, an NGINX server forwarding every request to one Node.js application is a reverse proxy without multi-server load balancing.
If NGINX distributes requests across three Node.js instances, it acts as both a reverse proxy and a load balancer.
Feature | Reverse Proxy | Load Balancer |
|---|---|---|
Main purpose | Manage and forward incoming requests | Distribute workload across available targets |
Routes requests | Yes | Yes, in typical implementations |
Requires multiple backend servers | No | Usually uses multiple targets |
Can handle TLS termination | Yes | Many implementations can |
Can perform caching | Some implementations can | Depends on the implementation |
Can provide health-based routing | Some implementations can | Common in load-balancing systems |
The distinction is primarily about responsibility rather than a completely separate category of technology.
Reverse Proxy vs API Gateway
An API gateway is another component commonly found in modern application architectures.
An API gateway acts as an entry point for API traffic and may provide API-specific capabilities such as authentication, authorization, request validation, quotas, rate limiting, and API version routing.
A reverse proxy focuses on receiving and forwarding traffic, although some reverse proxies can provide many of the same capabilities.
Feature | Reverse Proxy | API Gateway |
|---|---|---|
Primary focus | Traffic forwarding and backend access | API traffic management |
Request routing | Common | Common |
Load balancing | Common | May be supported |
Authentication | May be supported | Commonly supported |
API quotas and usage policies | Depends on the product | Common |
Request and response transformation | Depends on the product | Often supported |
API version management | Possible | Common in API-focused systems |
The boundaries can overlap. Some products serve as both reverse proxies and API gateways.
For a small application, a reverse proxy may be enough. For a large API platform with many teams, consumers, and access policies, an API gateway may provide additional useful functionality.
Reverse Proxy in Microservices Architecture
Microservices architectures divide an application into smaller services, each responsible for a particular business capability.
For example, an e-commerce application might contain:
User service.
Product service.
Order service.
Payment service.
Notification service.
Each service may run independently and have its own internal address.
A reverse proxy can provide a common entry point and route requests to the appropriate service.
Client
|
v
Reverse Proxy
|
+-----------+-----------+
| | |
v v v
User Service Product Service Order Service
| | |
+-----------+-----------+
|
Other ServicesExample routing rules:
/api/users/ → User service
/api/products/ → Product service
/api/orders/ → Order serviceThis allows the public application to expose a consistent API while keeping internal service addresses separate from public URLs.
In larger systems, a dedicated API gateway, service mesh, or cloud load balancer may also be used, depending on the requirements.
Common Reverse Proxy Use Cases
Reverse proxies are useful in many different environments.
1. Web Applications
A reverse proxy can sit in front of a frontend application and backend API, routing requests based on their URL paths.
2. E-Commerce Platforms
An e-commerce application can use a reverse proxy to distribute traffic, enforce selected security rules, and cache appropriate public resources.
3. SaaS Applications
Software-as-a-Service platforms can use reverse proxies to route requests to different application services and support centralized traffic management.
4. Content Delivery
Some reverse proxy services cache static assets and public content closer to users, reducing the number of requests that must reach the origin server.
5. Internal Applications
Organizations may place a reverse proxy in front of internal applications to control access and manage connections from authorized users.
6. Cloud Infrastructure
Cloud-based reverse proxies can provide routing, load balancing, TLS termination, and integration with security services.
Common Reverse Proxy Problems and How to Avoid Them
Although reverse proxies are powerful, incorrect configuration can cause unexpected behavior.
1. Incorrect Backend Address
If the configured backend address or port is incorrect, the proxy may return an error such as 502 Bad Gateway.
Solution: Verify that the backend is running and that the proxy server can reach it.
2. Incorrect URL Path Handling
An NGINX proxy_pass directive with or without a URI component can affect how request paths are forwarded.
For example:
location /api/ {
proxy_pass http://127.0.0.1:3000;
}In this configuration, the original request path is generally preserved.
For example:
/api/users → /api/usersBut consider:
location /api/ {
proxy_pass http://127.0.0.1:3000/;
}Here, the URI component / replaces the part of the original request URI matched by the location.
For a request to /api/users, the backend will generally receive /users.
Solution: Choose the configuration that matches your application's routes and test the actual paths being forwarded.
3. Incorrect Forwarded Headers
Applications sometimes need to know the original protocol, hostname, or client IP address.
If the proxy does not pass the appropriate headers, the application may generate incorrect redirects, log the proxy's IP address instead of the client's, or make incorrect security decisions.
Solution: Configure the required forwarded headers and make the application trust them only from known proxy infrastructure.
4. WebSocket Connections Not Working
Applications that use WebSockets may require additional proxy configuration for connection upgrades.
For example, NGINX can use a configuration like this for a WebSocket endpoint:
location /socket/ {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}This example is intended for a WebSocket route. Production deployments may need additional handling for connection headers, timeouts, and authentication.
5. HTTPS Redirect Loops
Redirect loops can occur when a reverse proxy terminates HTTPS but the backend incorrectly believes the original request used HTTP.
Solution: Configure the original-protocol headers correctly, ensure the application trusts the proxy, and configure HTTPS redirect behavior consistently across the proxy and backend.
6. Exposing Backend Ports Publicly
If backend services remain directly accessible from the internet, clients may bypass the reverse proxy's security and routing rules.
Solution: Restrict backend access through firewall rules, private networking, or loopback binding where appropriate.
7. Incorrect Caching Rules
Caching private or user-specific responses can expose sensitive information to other users.
Solution: Configure caching rules carefully and avoid public caching of sensitive responses. Test cache behavior for authenticated requests and cookies.
Best Practices for Using a Reverse Proxy
Follow these practices when configuring a reverse proxy for a real application:
Enable HTTPS: Protect communication between clients and the public endpoint.
Restrict backend access: Allow only trusted systems to connect directly to backend services.
Use appropriate timeouts: Configure connection, read, and send timeouts based on application behavior.
Configure logging: Record useful request and error information without unnecessarily logging sensitive data.
Use rate limiting where appropriate: Reduce the impact of excessive request rates.
Configure forwarded headers safely: Trust client-IP and protocol information only when supplied by trusted proxy infrastructure.
Monitor backend health: Track availability, latency, error rates, and resource usage.
Plan for proxy failures: Use redundancy where high availability is required.
Test configuration changes: Validate configuration syntax and test routes before deploying changes.
Review caching behavior: Ensure private and authenticated responses are not accidentally shared.
A reverse proxy should be treated as an important part of your application's infrastructure, not simply as a tool for forwarding requests.
Frequently Asked Questions (FAQs)
1. What is a reverse proxy in simple terms?
A reverse proxy is a server that sits between users and backend servers. It receives requests, forwards them to the appropriate backend, and returns the responses to users.
2. What is the main purpose of a reverse proxy?
Its main purpose is to manage incoming traffic to backend services. Depending on the implementation, it can also provide load balancing, caching, TLS termination, request routing, and access control.
3. Is NGINX a reverse proxy?
Yes. NGINX can act as a reverse proxy, a web server, a load balancer, and an HTTP cache.
4. Is a reverse proxy the same as a VPN?
No. A reverse proxy manages requests to backend services, while a VPN creates an encrypted network connection between a device or network and another network endpoint. They solve different problems, although both can be part of a broader security architecture.
5. Does a reverse proxy improve website performance?
It can. A reverse proxy may improve performance through caching, load balancing, compression, and efficient connection handling. The actual results depend on the configuration, workload, network, and backend architecture.
6. Can a reverse proxy hide a server's IP address?
It can help keep backend addresses hidden from ordinary clients. However, this protection is effective only if the origin server is not exposed through other routes and network access is appropriately restricted.
7. What is the difference between a reverse proxy and a web server?
A web server serves content and processes HTTP requests. A reverse proxy forwards requests to other servers. Some software, such as NGINX, can perform both roles.
8. Do Node.js applications need a reverse proxy?
Not every Node.js application needs one. For local development or simple deployments, a Node.js server may be sufficient. In production, a reverse proxy can help with HTTPS, routing, load balancing, and traffic management.
9. Is a reverse proxy a load balancer?
A reverse proxy can act as a load balancer, but the terms are not interchangeable in every context. A reverse proxy may forward all requests to one backend, while a load balancer distributes requests across multiple targets.
10. Which reverse proxy should beginners learn?
NGINX is a useful starting point because it is widely used and has extensive documentation. HAProxy, Caddy, and managed cloud proxy services are also worth exploring, depending on your use case.
Conclusion
A reverse proxy is an important component of modern web infrastructure. It sits between clients and backend servers, managing incoming requests and forwarding them to the appropriate services.
Beyond basic request forwarding, reverse proxies can support load balancing, TLS termination, caching, centralized routing, and additional security controls.
For developers building Node.js applications, APIs, microservices, or production websites, understanding reverse proxies helps explain how applications are deployed and how backend services are exposed safely.
Start by learning how NGINX forwards requests to a local application. Then explore HTTPS configuration, load balancing, timeouts, caching, and access controls as your application grows.
Understanding reverse proxies is an important step toward building web applications that are easier to manage, more reliable, and ready for production.
Technical author and software engineer at DevByte. Writing deep-dive tutorials on distributed systems, modern full-stack web architectures, and cloud deployments.


