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
MIME types configuration
📖 Scenario: You are setting up a web server using nginx. To serve files correctly, you need to configure MIME types so browsers know how to handle different file formats.
🎯 Goal: Configure nginx to recognize specific MIME types for file extensions and verify the configuration by printing the MIME types mapping.
📋 What You'll Learn
Create a dictionary called mime_types with exact file extension to MIME type mappings
Add a configuration variable default_type to specify the default MIME type
Use a loop to create a list of strings showing each extension and its MIME type
Print the list of MIME type mappings
💡 Why This Matters
🌍 Real World
Web servers like nginx use MIME types to tell browsers how to handle different files, such as showing images or running scripts.
💼 Career
Understanding MIME types and configuring them is essential for DevOps roles managing web servers and ensuring correct content delivery.
Progress0 / 4 steps
1
Create MIME types dictionary
Create a dictionary called mime_types with these exact entries: "html": "text/html", "css": "text/css", "js": "application/javascript", "png": "image/png", "jpg": "image/jpeg".
Nginx
Hint
Use curly braces {} to create a dictionary with keys as file extensions and values as MIME types.
2
Add default MIME type configuration
Add a variable called default_type and set it to the string "application/octet-stream" to specify the default MIME type for unknown files.
Nginx
Hint
Assign the string "application/octet-stream" to the variable default_type.
3
Create list of MIME type mappings
Use a for loop with variables ext and mime to iterate over mime_types.items(). Inside the loop, create a list called mime_list that contains strings in the format "extension: mime_type" for each entry.
Nginx
Hint
Initialize an empty list before the loop. Use f-strings to format each string inside the loop.
4
Print MIME type mappings
Write a print statement to display the mime_list variable.
Nginx
Hint
Use print(mime_list) to display the list of MIME type mappings.
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
Step 1: Understand MIME types role
MIME types tell browsers what kind of content is being sent, so they can handle it properly.
Step 2: Relate to nginx configuration
In nginx, configuring MIME types maps file extensions to content types for correct browser handling.
Final Answer:
To tell browsers how to handle different file types -> Option A
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
Step 1: Recall nginx MIME types syntax
The correct block is types { .ext mime/type; } with semicolons and dot before extension.
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
Step 1: Check the file extension
The file is named data.json, so the extension is .json.
Step 2: Match extension to MIME type in config
The config maps .json to application/json.
Final Answer:
application/json -> Option A
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
Step 1: Check syntax for each MIME type line
Each line must end with a semicolon; the line for .txt is missing it.
Step 2: Validate block name and extensions
The block name types is correct, and dots before extensions are required.
Final Answer:
Missing semicolon after .txt MIME type -> Option D
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
Step 1: Preserve existing MIME types
To keep existing types, include the default mime.types file inside the types block.
Step 2: Add new MIME type after include
After including existing types, add .abc application/x-abc; to extend the list.
Final Answer:
types { include mime.types; .abc application/x-abc; } -> Option C
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