0
0
Nginxdevops~30 mins

Default type handling in Nginx - Mini Project: Build & Apply

Choose your learning style9 modes available
Configure Default MIME Types in Nginx
📖 Scenario: You are setting up a simple web server using Nginx. You want to make sure that when users request files without an extension, Nginx serves them with a default MIME type.
🎯 Goal: Configure Nginx to serve files with a default MIME type of text/plain when the file type is not recognized.
📋 What You'll Learn
Create an Nginx configuration block for a server
Set the default_type directive to text/plain
Add a location block to serve files from /usr/share/nginx/html
Print the final configuration to verify the settings
💡 Why This Matters
🌍 Real World
Web servers like Nginx need to serve files with correct MIME types so browsers know how to handle them. Setting a default type helps when files lack extensions.
💼 Career
Understanding how to configure Nginx is essential for DevOps roles managing web servers and ensuring proper content delivery.
Progress0 / 4 steps
1
Create the basic server block
Create an Nginx server block with listen 80; and server_name localhost; inside http { }.
Nginx
Need a hint?

Remember to open and close the http and server blocks properly.

2
Set the default MIME type
Inside the server block, add the directive default_type text/plain; to set the default MIME type.
Nginx
Need a hint?

The default_type directive sets the MIME type for files without an extension or unknown types.

3
Add a location block to serve files
Inside the server block, add a location / block with root /usr/share/nginx/html; to serve files from that directory.
Nginx
Need a hint?

The location / block defines how to serve files for the root URL path.

4
Print the final Nginx configuration
Print the entire Nginx configuration to verify it includes default_type text/plain; and the location / block with the correct root.
Nginx
Need a hint?

Use a print statement to output the full configuration as a string exactly as written.