Nginx · The edge of your stack

How do you configure gzip compression?

EasygzipcompressionperformanceUpdated Oct 2026
Quiz this track

Short answer

Enable gzip, set a sensible compression level and minimum length, and list compressible text MIME types. Do not compress images, video or other already-compressed formats.

Compression reduces transfer size at the cost of CPU on both ends. Text formats benefit most. Images, fonts and video are already compressed, so recompressing them usually wastes CPU for little or no gain.

nginx
gzip on;
gzip_comp_level 5;
gzip_min_length 1024;
gzip_vary on;
gzip_proxied any;
gzip_types text/plain text/css application/json application/javascript application/xml image/svg+xml;
Level 5 is a common balance; level 9 costs more CPU for a small size improvement.

Related options

  • gzip_static serves a precompressed .gz file when available, saving CPU
  • gzip_vary tells caches that responses differ by Accept-Encoding
  • gzip_proxied controls compression for proxied requests
  • The Brotli module can improve ratios for text if it is installed
  • Compressing secrets together with attacker-controlled input can enable BREACH-style attacks
If a CDN or load balancer already compresses responses, compressing again in Nginx adds CPU and can confuse cache behavior. Compress at one layer.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Which content types should not be gzipped?
  2. 2Why does gzip_vary matter for caches?
  3. 3What is gzip_static?
  4. 4When would Brotli be a better choice?

Say it in the interview

I enable gzip for text responses, set a moderate level and a minimum length so tiny responses are not compressed, and enable gzip_vary for caches. I do not gzip images or video because they are already compressed. If the CDN already compresses, I avoid doing it twice. I also consider BREACH when sensitive data and attacker input share a compressed response.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Nginx mock interview and get scored feedback on depth, clarity and confidence.