Back to Docs
Documentation

How to Set Up Nginx Reverse Proxy

Complete guide to configuring Nginx as a reverse proxy for your web applications.

What is a Reverse Proxy?

A reverse proxy sits between client devices and your backend servers, forwarding client requests to the appropriate server. Nginx is one of the most popular choices for reverse proxy due to its high performance and low resource consumption.

Basic Reverse Proxy Configuration

The simplest reverse proxy setup forwards all traffic from one domain to a backend application:

server {
    listen 80;
    server_name app.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; } }

Passing Headers

When running behind a reverse proxy, your backend needs to know the real client IP and protocol. The key headers are:

  • X-Real-IP — The actual client IP address
  • X-Forwarded-For — Chain of proxy IPs
  • X-Forwarded-Proto — Original protocol (http/https)
  • Host — The original host header

WebSocket Support

To proxy WebSocket connections, add the Upgrade headers:

location /ws {
    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;
}

Load Balancing with Upstream

For high-availability setups, use an upstream block:

upstream backend {
    least_conn;
    server 10.0.0.1:8080 weight=3;
    server 10.0.0.2:8080 weight=2;
    server 10.0.0.3:8080 weight=1;
}

server { listen 80; server_name api.example.com;

location / { proxy_pass http://backend; } }

Use Our Generator

Instead of writing these configs by hand, use Configen to build your reverse proxy configuration visually!

Ready to build your config?

Use Configen to generate or audit your server configuration — no coding required.