Chapter

Performance and caching

Make nginx faster with compression, static asset caching, proxy caching, and sensible worker and keepalive settings.

Nginx Basics 5 Lessons from courses

About this chapter

Small config changes can make your site noticeably faster. This chapter covers gzip compression, caching static assets, caching backend responses, tuning workers, and reusing connections with keepalive.

Lessons from courses

  1. 1 Gzip compression Enable nginx gzip compression to shrink text responses. Set gzip_types, gzip_comp_level, gzip_min_length, and skip what you should never compress.
  2. 2 Caching static assets Cache static assets in nginx so browsers reuse CSS, JS, and images. Set expires and Cache-Control, pick safe cache times, and handle cache-busting.
  3. 3 Proxy caching Set up nginx proxy caching with proxy_cache_path and proxy_cache. Cache backend responses, tune proxy_cache_valid, and read the X-Cache-Status header.
  4. 4 Workers and connections Understand nginx worker_processes and worker_connections: what they control, how they set the connection ceiling, and the defaults you rarely change.
  5. 5 Keepalive connections Reuse connections with nginx keepalive: keepalive_timeout for clients and upstream keepalive for backends, plus the three lines pooling needs.
Nginx Basics Go to course