Skip to main content

Performance Optimization

Nginx is fast out of the box. These settings push it toward its limits — squeezing out lower latency, higher throughput, and better cache hit rates.


What You Will Learn

  • How to enable HTTP/2 and HTTP/3 (QUIC)
  • How gzip and Brotli compression work and when to use each
  • How Nginx's proxy cache works and how to configure it for PHP and upstream apps
  • How to tune worker processes, connections, and file descriptor limits
  • How to use sendfile, tcp_nopush, and tcp_nodelay correctly
  • Browser caching — setting Cache-Control and Expires headers

Topics in This Module


Quick Performance Wins (in order of impact)

OptimizationImpactDirective
Enable OPcache for PHP-FPMVery Highphp.ini opcache.enable=1
Enable HTTP/2Highlisten 443 ssl http2
Enable gzipHighgzip on; gzip_types ...
Set browser cache headersHighexpires 1y; for static assets
Use UNIX socket for PHP-FPMMediumfastcgi_pass unix:/run/php/...
Enable sendfileMediumsendfile on; in http block
Enable BrotliMediumrequires module install
Tune worker_connectionsMediummatch ulimit -n

Success Checkpoint

By the end of this module you should be able to enable HTTP/2, configure gzip, set browser cache headers, and tune worker settings for your server's CPU and RAM.