Why might gzip not compress CSS files as expected?
medium
A. gzip is disabled by default
B. gzip_types does not include CSS MIME type
C. gzip_min_length value is too high
D. Missing semicolon after gzip_min_length directive
Solution
Step 1: Check syntax of gzip_min_length
The directive gzip_min_length 512 is missing a semicolon at the end, causing nginx to ignore or error on it.
Step 2: Understand effect of syntax error
Without proper syntax, gzip_min_length may not apply correctly, causing unexpected behavior in compression.
Final Answer:
Missing semicolon after gzip_min_length directive -> Option D
Quick Check:
Every directive must end with semicolon [OK]
Hint: Always end nginx directives with semicolon [OK]
Common Mistakes:
Forgetting semicolon at directive end
Assuming gzip_types excludes CSS by default
Thinking gzip is off unless explicitly enabled
5. You want to compress only JSON and JavaScript files larger than 1500 bytes using gzip in nginx. Which configuration snippet achieves this correctly?
hard
A. gzip on;\ngzip_types application/json application/javascript;\ngzip_min_length 1500;
B. gzip on;\ngzip_types json js;\ngzip_min_length 1500;
C. gzip on;\ngzip_types application/json application/javascript;\ngzip_min_length 1500
D. gzip on;\ngzip_types application/json application/javascript;\ngzip_min_length=1500;
Solution
Step 1: Verify gzip is enabled
The directive gzip on; correctly enables gzip compression.
Step 2: Check gzip_types values
Use correct MIME types: application/json and application/javascript are valid. Short forms like 'json' or 'js' are invalid.
Step 3: Confirm gzip_min_length syntax
The directive must end with semicolon and no equals sign. gzip_min_length 1500; is correct.
Final Answer:
gzip on;\ngzip_types application/json application/javascript;\ngzip_min_length 1500; -> Option A