0
0
Nginxdevops~15 mins

MIME types configuration in Nginx - Mini Project: Build & Apply

Choose your learning style9 modes available
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
Need a 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
Need a 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
Need a 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
Need a hint?

Use print(mime_list) to display the list of MIME type mappings.