0
0
NginxConceptBeginner · 3 min read

What is Reverse Proxy in Nginx: Simple Explanation and Example

A reverse proxy in nginx is a server that receives client requests and forwards them to one or more backend servers. It acts like a middleman, hiding the backend servers from clients and managing traffic, security, and load balancing.
⚙️

How It Works

Imagine you have a receptionist at an office building who takes visitors' requests and directs them to the right department inside. A reverse proxy in Nginx works similarly. It listens for requests from users on the internet and then forwards those requests to one or more internal servers that actually handle the work.

This setup helps keep the internal servers hidden from direct access, improving security. It also allows Nginx to manage traffic by distributing requests evenly, caching responses to speed up delivery, and handling encryption.

💻

Example

This example shows a simple Nginx reverse proxy configuration that forwards requests to a backend server running on localhost port 3000.

nginx
server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://localhost:3000;
        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;
    }
}
Output
When a user visits http://example.com, Nginx forwards the request to http://localhost:3000 and returns the backend server's response to the user.
🎯

When to Use

Use a reverse proxy in Nginx when you want to:

  • Protect backend servers by hiding them from direct internet access.
  • Distribute incoming traffic across multiple servers to balance load.
  • Cache responses to improve speed and reduce backend load.
  • Enable SSL/TLS encryption at the proxy level.
  • Serve multiple applications from one public IP or domain.

For example, a company might use Nginx as a reverse proxy to route requests to different web apps running on separate servers, all while providing a single secure entry point.

Key Points

  • A reverse proxy forwards client requests to backend servers.
  • It improves security by hiding backend details.
  • It can balance load and cache content.
  • Nginx is a popular tool for reverse proxying.
  • Configuration involves the proxy_pass directive.

Key Takeaways

A reverse proxy in Nginx forwards client requests to backend servers securely and efficiently.
It hides backend servers from direct access, improving security.
Use reverse proxy to balance load, cache content, and manage SSL.
The core Nginx directive for reverse proxy is proxy_pass.
Reverse proxy helps serve multiple apps from one public endpoint.