Learn NGINX

High-performance web server, reverse proxy, load balancer and cache

18 lessons · 3 hours · 4 levels · covers NGINX 1.30

NGINX is an event-driven web server that serves static files, terminates TLS and proxies requests to application servers. It sits in front of a large share of the world's websites as a reverse proxy, load balancer and HTTP cache. Knowing how to configure it is a core skill for deploying any web application.

Before you start

NGINX builds on these; the tree links to the exact lessons you need.

How deep do you want to go?

1. EssentialsRead and write simple code, do the everyday basics6 lessons · 56 min in total
2. PracticalUse it productively at work, with the usual idioms11 lessons · 2 hours in total
3. AdvancedThe less common features, performance and trade-offs15 lessons · 3 hours in total
4. ExpertInternals and the edge cases experts know18 lessons · 3 hours in total

The NGINX tree

NGINXWhat NGINX doesWhat NGINX doesInstalling, testing and reloadingInstalling, testing andreloadingConfiguration structure: directives and contextsConfigurationstructure: directive…Server blocks: listen and server_nameServer blocks: listenand server_nameStatic files: root, alias and try_filesStatic files: root, aliasand try_filesHow location blocks are matchedHow location blocksare matchedReverse proxy with proxy_passReverse proxy withproxy_passAccess and error logsAccess and errorlogsHTTPS and TLS terminationHTTPS and TLSterminationRedirects, rewrites and variablesRedirects, rewritesand variablesLoad balancing with upstreamLoad balancing withupstreamYour first requests: GET and downloadsYour first requests:GET and downloadsSeeing headers: -i, -I, -v and -HSeeing headers: -i, -I,-v and -H
Essentials and Practical shown (11 of 18 lessons); the full list is below. Click a lesson to read it.

All 18 lessons, in order

Getting started

  1. What NGINX does · Essentials · 6 min

    NGINX as web server, reverse proxy, load balancer and cache, and why its event-driven design handles many connections cheaply.

  2. Installing, testing and reloading · Essentials · 8 min

    Install NGINX, find its files, validate configuration with nginx -t and apply it with a graceful reload.

  3. Configuration structure: directives and contexts · Essentials · 10 min

    Read nginx.conf: simple and block directives, the main, events, http, server and location contexts, includes and inheritance.

Serving sites

  1. Server blocks: listen and server_name · Essentials · 10 min

    Host several sites on one NGINX with server blocks, and understand how a request is matched by port, name and default_server.

  2. Static files: root, alias and try_files · Essentials · 10 min

    Map URLs to files with root and alias, choose index files, and use try_files for fallbacks such as single-page apps.

  3. How location blocks are matched · Essentials · 12 min

    Learn the exact order NGINX uses to pick a location: exact match, longest prefix, ^~, then regular expressions in file order.

  4. Access and error logs · Practical · 10 min

    Configure access_log and error_log, define log formats including JSON and upstream timings, and read logs to debug.

  5. Redirects, rewrites and variables · Practical · 12 min

    Redirect with return, rewrite URIs with regex captures, and use built-in variables like $host, $uri and $args.

Reverse proxy and load balancing

  1. Reverse proxy with proxy_pass · Practical · 14 min

    Forward requests to an application server with proxy_pass, pass the right headers, and get the trailing-slash URI rules right.

  2. Load balancing with upstream · Practical · 12 min

    Spread traffic across backends with upstream groups, choose a balancing method, and handle failures and keepalive connections.

  3. WebSockets, timeouts and buffering · Advanced · 12 min

    Proxy WebSocket and long-lived connections with the Upgrade headers, tune timeouts, and know when to turn proxy buffering off.

TLS and access control

  1. HTTPS and TLS termination · Practical · 14 min

    Serve HTTPS with certificates, enable HTTP/2, redirect HTTP to HTTPS and choose sane TLS settings.

  2. Access control and security headers · Advanced · 10 min

    Restrict locations by IP with allow/deny, add basic authentication, set security headers and hide version details.

Caching and traffic control

  1. Proxy caching · Advanced · 14 min

    Cache backend responses with proxy_cache_path and proxy_cache, control validity, serve stale content and debug with cache status.

  2. Rate and connection limiting · Advanced · 12 min

    Throttle clients with limit_req_zone and limit_req, understand burst and nodelay, and cap concurrent connections.

Internals and tuning

  1. Master, workers and the event loop · Expert · 12 min

    How the master and worker processes divide work, how many connections NGINX can hold, and what really happens during reload and upgrade.

  2. Request phases, if and map · Expert · 14 min

    Follow a request through NGINX's processing phases and understand why if inside location is dangerous and map is preferred.

  3. Tuning compression, files and keepalive · Expert · 14 min

    Tune gzip, sendfile, open_file_cache, keepalive and buffers, and know which settings actually matter.