Bird
Raised Fist0
Nginxdevops~20 mins

MIME types configuration 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
🎖️
MIME Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Identify MIME type served by Nginx
Given the following Nginx configuration snippet, what MIME type will Nginx serve for a file named example.svg?
Nginx
types {
    text/html  html;
    image/svg+xml  svg;
    application/javascript  js;
}

location / {
    root /var/www/html;
}
Aapplication/octet-stream
Btext/html
Capplication/javascript
Dimage/svg+xml
Attempts:
2 left
💡 Hint
Check the MIME type associated with the .svg extension in the types block.
Configuration
intermediate
2:00remaining
Correct MIME type for JSON files
Which configuration snippet correctly sets the MIME type for files with the .json extension to application/json in Nginx?
A
types {
    application/json json;
}
B
types {
    text/json json;
}
C
types {
    application/javascript json;
}
D
types {
    application/json js;
}
Attempts:
2 left
💡 Hint
The MIME type must be application/json and the extension json.
Troubleshoot
advanced
2:00remaining
Why is Nginx serving wrong MIME type?
You configured Nginx to serve .woff2 files with MIME type font/woff2 but browsers still treat them as application/octet-stream. What is the most likely cause?
AThe <code>mime.types</code> file is not included in the main configuration.
BThe <code>types</code> block is missing the <code>woff2</code> extension mapping.
CThe <code>default_type</code> directive is set to <code>application/octet-stream</code> and overrides types.
DThe <code>root</code> directive is incorrect, causing files not to be found.
Attempts:
2 left
💡 Hint
Check if the standard MIME types file is loaded by Nginx.
🔀 Workflow
advanced
2:00remaining
Order of MIME type resolution in Nginx
In what order does Nginx determine the MIME type for a requested file?
ACheck <code>types</code> block in current context → Use <code>default_type</code> if no match → Check <code>mime.types</code> file
BCheck <code>types</code> block in current context → Check <code>mime.types</code> file → Use <code>default_type</code> if no match
CCheck <code>mime.types</code> file → Check <code>types</code> block in current context → Use <code>default_type</code> if no match
DUse <code>default_type</code> first → Check <code>types</code> block → Check <code>mime.types</code> file
Attempts:
2 left
💡 Hint
Nginx first looks at local types, then global mime.types, then default.
Best Practice
expert
3:00remaining
Best practice for custom MIME types in Nginx
What is the best practice to add a custom MIME type for a new file extension .abc without modifying the default mime.types file?
AAdd a <code>types</code> block with the new mapping inside the <code>http</code> block in your main config.
BDirectly edit the <code>mime.types</code> file to add the new extension and reload Nginx.
CCreate a separate file with the new MIME type and include it in the main config using the <code>include</code> directive.
DUse the <code>default_type</code> directive to set the MIME type for .abc files.
Attempts:
2 left
💡 Hint
Avoid editing default files; use includes for customizations.

Practice

(1/5)
1. What is the main purpose of configuring MIME types in nginx?
easy
A. To tell browsers how to handle different file types
B. To set the server's IP address
C. To define user access permissions
D. To configure server logging format

Solution

  1. Step 1: Understand MIME types role

    MIME types tell browsers what kind of content is being sent, so they can handle it properly.
  2. Step 2: Relate to nginx configuration

    In nginx, configuring MIME types maps file extensions to content types for correct browser handling.
  3. Final Answer:

    To tell browsers how to handle different file types -> Option A
  4. Quick Check:

    MIME types = browser file handling [OK]
Hint: MIME types = file type instructions for browsers [OK]
Common Mistakes:
  • Confusing MIME types with server IP settings
  • Thinking MIME types control user permissions
  • Mixing MIME types with logging configuration
2. Which of the following is the correct syntax to define MIME types in nginx configuration?
easy
A. mime_types { html text/html; css text/css; }
B. types { .html text/html; .css text/css; }
C. types { html: text/html; css: text/css; }
D. mime { .html = text/html; .css = text/css; }

Solution

  1. Step 1: Recall nginx MIME types syntax

    The correct block is types { .ext mime/type; } with semicolons and dot before extension.
  2. Step 2: Compare options

    types { .html text/html; .css text/css; } matches correct syntax with types { .html text/html; .css text/css; }.
  3. Final Answer:

    types { .html text/html; .css text/css; } -> Option B
  4. Quick Check:

    Correct syntax uses 'types' block with dot extensions [OK]
Hint: Use 'types { .ext mime/type; }' with dots and semicolons [OK]
Common Mistakes:
  • Omitting dots before file extensions
  • Using colons or equals instead of spaces
  • Wrong block name like 'mime_types' or 'mime'
3. Given this nginx config snippet:
types {
  .json application/json;
  .xml application/xml;
}

What MIME type will nginx send for a file named data.json?
medium
A. application/json
B. text/plain
C. application/xml
D. text/html

Solution

  1. Step 1: Check the file extension

    The file is named data.json, so the extension is .json.
  2. Step 2: Match extension to MIME type in config

    The config maps .json to application/json.
  3. Final Answer:

    application/json -> Option A
  4. Quick Check:

    .json = application/json [OK]
Hint: Match file extension to MIME type in 'types' block [OK]
Common Mistakes:
  • Confusing .json with .xml MIME type
  • Assuming default text/plain without config
  • Ignoring the dot before extension
4. You added this to your nginx config:
types {
  .txt text/plain
  .md text/markdown;
}

Why might nginx fail to start?
medium
A. MIME types cannot include 'text/markdown'
B. Wrong block name 'types' instead of 'mime_types'
C. File extensions must not have dots
D. Missing semicolon after .txt MIME type

Solution

  1. Step 1: Check syntax for each MIME type line

    Each line must end with a semicolon; the line for .txt is missing it.
  2. Step 2: Validate block name and extensions

    The block name types is correct, and dots before extensions are required.
  3. Final Answer:

    Missing semicolon after .txt MIME type -> Option D
  4. Quick Check:

    Every MIME type line ends with semicolon [OK]
Hint: Check semicolons after each MIME type line [OK]
Common Mistakes:
  • Forgetting semicolon at line end
  • Changing 'types' block name incorrectly
  • Removing dots before extensions
5. You want nginx to serve a new file type .abc with MIME type application/x-abc. Which config snippet correctly adds this without removing existing types?
hard
A. mime_types { .abc application/x-abc; }
B. types { .abc application/x-abc; }
C. types { include mime.types; .abc application/x-abc; }
D. types { .abc = application/x-abc; }

Solution

  1. Step 1: Preserve existing MIME types

    To keep existing types, include the default mime.types file inside the types block.
  2. Step 2: Add new MIME type after include

    After including existing types, add .abc application/x-abc; to extend the list.
  3. Final Answer:

    types { include mime.types; .abc application/x-abc; } -> Option C
  4. Quick Check:

    Include existing types then add new ones [OK]
Hint: Include mime.types before adding new MIME types [OK]
Common Mistakes:
  • Overwriting existing types by not including mime.types
  • Using wrong block name 'mime_types'
  • Using equals sign instead of space