Server

Nginx

Nginx is a web server and reverse proxy that handles connections, serves static files and passes dynamic requests to an application. Many WordPress and Node sites put it in front of PHP-FPM or an app server.

How it is measured

Read the access log for status codes, request time and upstream response time, and the error log for upstream problems. Adding `$request_time` and `$upstream_response_time` to the log format lets you split proxy time from app time.

Check `nginx -t` before every reload, and the stub_status page for active connections, accepted and handled counts.

Worked example

A blog on a 2 GB VPS runs Nginx in front of PHP-FPM. The access log shows `$request_time` of 1.9 seconds with `$upstream_response_time` of 1.85 seconds on /feed/, while static files return in 4 ms. The proxy is quick, and PHP is the slow part.

Enabling `fastcgi_cache` for /feed/ with a 5 minute validity moves it to 6 ms and removes about 40 percent of PHP-FPM work.

How it differs

Nginx is a specific program. A reverse proxy is the role it can play, forwarding requests for an app. Nginx also does static files, caching, TLS and load balancing, which a bare reverse proxy concept does not require. Other programs, like Caddy or HAProxy, fill the same role with different configuration.

Common errors

Editing the config and reloading without `nginx -t`. Leaving default `proxy_read_timeout` and getting 504 on long requests. Forgetting to pass the real client IP to the app. Setting worker_connections above the file descriptor limit. Caching pages with cookies and serving one person's data to another.

In practice

Add upstream timing to your access log format and review the slowest 20 paths. Turn on gzip or brotli for text, set cache headers for static files, and keep the config in version control.

See also

Reverse proxy, HTTP 502

Sources

Count this on a real site.

Watch my website