Nginx
Nginx is a high-performance web server that can also function as a reverse proxy, load balancer, and HTTP cache. This guide demonstrates how to configure Nginx for reverse proxying and load balancing using Docker containers.
What is a Reverse Proxy?
A reverse proxy sits between clients and backend servers, forwarding client requests to the appropriate backend server and then returning the server's response back to the client. Benefits include:
- Load distribution - Spread requests across multiple servers
- SSL termination - Handle SSL/TLS encryption/decryption
- Caching - Store frequently requested content
- Security - Hide backend server details from clients
- Compression - Reduce bandwidth usage
In This Section
- Reverse Proxy — Configuring Nginx as a reverse proxy with Docker — basic setup, separate ports, and name-based virtual hosts
- Load Balancing — Load balancing with Nginx — upstream groups, balancing methods, health checks, and advanced configuration
- TLS / Let's Encrypt — Configuring TLS/SSL in Nginx, including automated certificates with Let's Encrypt (Certbot) on host and in Docker
- Monitoring & Troubleshooting — Monitoring Nginx with the status module, useful operational commands, and solutions to common issues
- Best Practices — Nginx security headers, rate limiting, and caching best practices
Resources
- Nginx Documentation
- Nginx Load Balancing
- Nginx Reverse Proxy
- Nginx SSL Configuration
- Mozilla SSL Configuration Generator
Header reference:
proxy_set_header— ngx_http_proxy_module — set/override request headers to the backendadd_header— ngx_http_headers_module — add response headers (and the inheritance caveat)- Nginx embedded variables —
$host,$remote_addr,$scheme, and the rest used in header values - MDN HTTP Headers reference — authoritative definition of every request/response header
- OWASP Secure Headers Project — recommended security response headers and values
- MDN:
Forwardedheader (RFC 7239) — the standardized alternative to theX-Forwarded-*conventions