Bird
Raised Fist0
Nginxdevops~20 mins

Gzip compression in Nginx - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Gzip Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Check if gzip is enabled in nginx
You run the command nginx -T | grep gzip to check gzip settings. What output indicates gzip is enabled?
Nginx
nginx -T | grep gzip
Agzip off;
Bgzip on;
C# gzip on;
Dgzip_disable "msie6";
Attempts:
2 left
💡 Hint
Look for the directive that explicitly turns gzip on without being commented out.
Configuration
intermediate
2:00remaining
Configure gzip to compress only text files
Which nginx configuration snippet correctly enables gzip compression only for text-based files?
A
gzip on;
gzip_types text/plain text/css application/javascript;
B
gzip on;
gzip_types application/octet-stream;
C
gzip off;
gzip_types text/plain;
D
gzip on;
gzip_types image/png image/jpeg;
Attempts:
2 left
💡 Hint
gzip_types defines which MIME types are compressed. Text files have MIME types like text/plain or text/css.
Troubleshoot
advanced
2:30remaining
Why is gzip not compressing responses?
You enabled gzip in nginx but responses are still not compressed. Which of these is a likely cause?
AThe <code>Content-Length</code> header is missing in responses.
BThe <code>gzip_min_length</code> is set too low.
CThe <code>gzip_disable</code> directive disables gzip for the client browser.
DThe server is sending <code>Content-Encoding: gzip</code> header manually.
Attempts:
2 left
💡 Hint
Check if gzip is disabled for certain browsers or clients.
Best Practice
advanced
2:00remaining
Optimal gzip buffer size configuration
Which buffer size setting is recommended to optimize gzip compression performance in nginx?
Agzip_buffers 4 16k;
Bgzip_buffers 1 1k;
Cgzip_buffers 16 64k;
Dgzip_buffers 2 512k;
Attempts:
2 left
💡 Hint
Buffers should be moderate size to balance memory and compression efficiency.
🔀 Workflow
expert
3:00remaining
Order the steps to enable gzip compression in nginx
Put these steps in the correct order to enable gzip compression on an nginx server.
A2,1,3,4
B1,2,4,3
C1,3,2,4
D1,2,3,4
Attempts:
2 left
💡 Hint
You must edit config before testing and reloading.

Practice

(1/5)
1. What is the main purpose of enabling gzip compression in nginx?
easy
A. To block certain file types from being served
B. To increase the server's CPU usage for better performance
C. To encrypt data between server and client
D. To reduce the size of files sent to the browser, speeding up page load

Solution

  1. Step 1: Understand gzip compression purpose

    Gzip compresses files to reduce their size before sending to the browser.
  2. Step 2: Connect compression to page load speed

    Smaller files load faster, improving website speed and user experience.
  3. Final Answer:

    To reduce the size of files sent to the browser, speeding up page load -> Option D
  4. Quick Check:

    gzip compression = smaller files = faster load [OK]
Hint: Remember gzip shrinks files to speed up loading [OK]
Common Mistakes:
  • Thinking gzip increases CPU for performance
  • Confusing gzip with encryption
  • Believing gzip blocks files
2. Which of the following is the correct way to enable gzip compression in nginx configuration?
easy
A. gzip on;
B. gzip enable;
C. enable gzip;
D. gzip true;

Solution

  1. Step 1: Recall nginx gzip syntax

    The correct directive to enable gzip is gzip on;.
  2. Step 2: Check other options for syntax errors

    Options A, C, and D use invalid keywords or syntax not recognized by nginx.
  3. Final Answer:

    gzip on; -> Option A
  4. Quick Check:

    Enable gzip with 'gzip on;' [OK]
Hint: Use exact directive 'gzip on;' to enable gzip [OK]
Common Mistakes:
  • Using 'gzip enable;' instead of 'gzip on;'
  • Writing 'enable gzip;' which is invalid
  • Using 'gzip true;' which is not recognized
3. Given this nginx snippet:
gzip on;
gzip_types text/plain application/json;

Which file types will be compressed when served?
medium
A. All file types are compressed
B. Only text/plain and application/json files
C. No files are compressed because gzip_types is incomplete
D. Only binary files are compressed

Solution

  1. Step 1: Analyze gzip_types directive

    The directive specifies only text/plain and application/json MIME types for compression.
  2. Step 2: Understand gzip on directive effect

    With gzip on;, only the listed types in gzip_types are compressed.
  3. Final Answer:

    Only text/plain and application/json files -> Option B
  4. Quick Check:

    gzip_types limits compression to listed types [OK]
Hint: gzip_types controls which file types get compressed [OK]
Common Mistakes:
  • Assuming all files compress by default
  • Thinking gzip_types must list all types including binaries
  • Believing gzip_types disables compression
4. You added gzip on; and gzip_types text/html; to nginx.conf but compression is not working. What is the likely mistake?
medium
A. Enabling gzip disables compression by default
B. Using gzip_types with only one type
C. Forgetting to reload nginx after config change
D. Missing gzip_disable directive

Solution

  1. Step 1: Check nginx reload requirement

    After config changes, nginx must be reloaded to apply new settings.
  2. Step 2: Evaluate other options

    Using one type in gzip_types is valid; gzip on enables compression; gzip_disable disables it for some clients but is optional.
  3. Final Answer:

    Forgetting to reload nginx after config change -> Option C
  4. Quick Check:

    Reload nginx to apply gzip changes [OK]
Hint: Always reload nginx after config edits [OK]
Common Mistakes:
  • Not reloading nginx after config update
  • Thinking gzip_types must list many types
  • Confusing gzip_disable as required
5. You want to compress HTML, CSS, and JavaScript files in nginx. Which configuration snippet correctly enables gzip for these types?
hard
A. gzip on;\ngzip_types text/html text/css application/javascript;
B. gzip on;\ngzip_types html css js;
C. gzip enable;\ngzip_types text/html text/css application/javascript;
D. gzip on;\ngzip_types text/html text/css js;

Solution

  1. Step 1: Verify gzip enabling syntax

    The correct directive to enable gzip is gzip on;, not gzip enable;.
  2. Step 2: Check MIME types in gzip_types

    File types must be specified by their MIME types: text/html, text/css, and application/javascript. Using extensions like 'html', 'css', or 'js' is invalid.
  3. Final Answer:

    gzip on;\ngzip_types text/html text/css application/javascript; -> Option A
  4. Quick Check:

    Use 'gzip on;' and correct MIME types [OK]
Hint: Use MIME types, not file extensions, in gzip_types [OK]
Common Mistakes:
  • Using 'gzip enable;' instead of 'gzip on;'
  • Listing file extensions instead of MIME types
  • Omitting JavaScript MIME type