Configuring Nginx as a Reverse Proxy
2 min read
- Authors
- Name
- Vijaykumar Rajendran
- @vijayrajendran_

Table of Contents
Configuring Reverse Proxy
Complete Production Setup
server {
listen 80;
server_name api.example.com;
location / {
proxy_pass http://backend:3000;
# Forward original headers
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;
# Timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
# Buffering
proxy_buffering on;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
}
}
Key Directives
proxy_pass- Where to forward the requestproxy_set_header- Add or modify headersproxy_connect_timeout- Connection establishment timeoutproxy_read_timeout- Time to read responseproxy_buffering- Buffer backend responses
Important Headers to Forward
| Header | Purpose |
|---|---|
Host | Original host |
X-Real-IP | Real client IP |
X-Forwarded-For | All IPs in chain |
X-Forwarded-Proto | Original protocol (http/https) |
Production-ready!