Nginx and Reverse Proxies
How Nginx handles thousands of connections with a few event-driven workers, and how to use it for load balancing, TLS, caching and rate limiting.
What Nginx is
Nginx (pronounced "engine-x") is a web server and reverse proxy: a server that sits in front of your application servers, accepts client connections and forwards requests to them. The client only ever talks to Nginx.
One process can play several roles at once:
- Static file server. Sends images, CSS and JavaScript straight from disk.
- Reverse proxy. Forwards dynamic requests to an app (Node, Java, Python).
- Load balancer (spreads requests over several servers) at layer 7, meaning it understands HTTP.
- TLS terminator. Handles encryption so apps speak plain HTTP inside the private network.
- Cache and rate limiter. Stores responses and caps request rates.
It is the same idea as the proxies in the CDN lesson, but you run it yourself, close to your servers.
1 of 9