0
0
Nginxdevops~10 mins

Gzip configuration (types, min_length) in Nginx - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Gzip configuration (types, min_length)
Start nginx config
Enable gzip
Set gzip_min_length
Set gzip_types
Request received
Check content type
Check content length
Compress response
Send response
This flow shows how nginx checks gzip settings: enabling gzip, setting minimum length, and types to compress, then deciding to compress or not based on request.
Execution Sample
Nginx
gzip on;
gzip_min_length 1000;
gzip_types text/plain application/json;
This config enables gzip, compresses responses only if size >= 1000 bytes, and only for specified content types.
Process Table
StepActionContent-TypeContent-LengthConditionResult
1Request receivedtext/plain1500Content-Type in gzip_types? YesCheck content length
2Check content lengthtext/plain1500Length >= gzip_min_length? YesCompress response
3Send responsetext/plain1500CompressedResponse sent compressed
4Request receivedimage/png2000Content-Type in gzip_types? NoSend uncompressed
5Send responseimage/png2000Not compressedResponse sent uncompressed
6Request receivedapplication/json800Content-Type in gzip_types? YesCheck content length
7Check content lengthapplication/json800Length >= gzip_min_length? NoSend uncompressed
8Send responseapplication/json800Not compressedResponse sent uncompressed
💡 Requests processed based on content type and length compared to gzip settings.
Status Tracker
VariableStartAfter Request 1After Request 2After Request 3
gzipoffononon
gzip_min_length0100010001000
gzip_typesnonetext/plain application/jsontext/plain application/jsontext/plain application/json
Content-Typenonetext/plainimage/pngapplication/json
Content-Length015002000800
Compressedfalsetruefalsefalse
Key Moments - 3 Insights
Why does nginx not compress the image/png response even though its size is large?
Because image/png is not listed in gzip_types (see execution_table row 4), nginx skips compression for that content type.
What happens if the content length is less than gzip_min_length?
Nginx sends the response uncompressed (see execution_table rows 6-8), even if the content type matches gzip_types.
Does enabling gzip alone guarantee compression of all responses?
No, gzip must be enabled, and the response must meet both content type and minimum length conditions (see execution_table rows 1-3).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step is the response compressed for a text/plain content type?
AStep 2
BStep 3
CStep 1
DStep 4
💡 Hint
Check the 'Result' column for 'Response sent compressed' for text/plain content type.
According to the variable tracker, what is the value of gzip_min_length after configuration?
A0
B500
C1000
D1500
💡 Hint
Look at the 'gzip_min_length' row after 'After Request 1' in variable_tracker.
If gzip_types included 'image/png', what would change in the execution table for step 4?
AResponse would be compressed
BResponse would still be uncompressed
CContent length would change
DRequest would be rejected
💡 Hint
Refer to step 4 where content type is image/png and compression depends on gzip_types.
Concept Snapshot
nginx gzip config:
gzip on; # enable gzip
gzip_min_length 1000; # min size to compress
gzip_types text/plain application/json; # compress only these types
Requests smaller or types not listed are sent uncompressed.
Full Transcript
This visual execution shows how nginx decides to compress responses using gzip. First, gzip must be enabled. Then nginx checks if the response content type matches the gzip_types list. If yes, it checks if the response size is at least gzip_min_length bytes. Only then does it compress the response. Otherwise, it sends the response uncompressed. For example, a text/plain response of 1500 bytes is compressed, but an image/png response is not compressed because it is not in gzip_types. Also, a small application/json response under 1000 bytes is not compressed. This helps save CPU by compressing only useful responses.