0
0
Nginxdevops~20 mins

Default type handling in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
NGINX MIME Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How does NGINX determine the MIME type of a served file by default?

When NGINX serves a static file, how does it decide which MIME type to send in the Content-Type header if no explicit type is set?

AIt uses the file extension and the <code>mime.types</code> file to map extensions to MIME types.
BIt always sends <code>application/octet-stream</code> regardless of file type.
CIt guesses the MIME type by reading the file content.
DIt uses the <code>default_type</code> directive only and ignores file extensions.
Attempts:
2 left
💡 Hint

Think about how web servers usually identify file types for HTTP headers.

💻 Command Output
intermediate
2:00remaining
Output of NGINX with missing MIME type for .xyz files

Given this NGINX configuration snippet:

http {
    include       mime.types;
    default_type  application/octet-stream;
}
server {
    listen 8080;
    location / {
        root /usr/share/nginx/html;
    }
}

If a client requests file.xyz (an unknown extension), what Content-Type header will NGINX send?

ANo Content-Type header is sent
BContent-Type: application/octet-stream
CContent-Type: application/xyz
DContent-Type: text/plain
Attempts:
2 left
💡 Hint

Consider what default_type is set to and what happens if the extension is unknown.

Configuration
advanced
2:00remaining
Correctly setting default MIME type for unknown files

You want NGINX to send text/plain as the default MIME type for files with unknown extensions. Which configuration snippet achieves this?

A
http {
    include mime.types;
    default_type text/plain;
}
B
http {
    default_type text/plain;
    include mime.types;
}
C
http {
    include mime.types;
    default_type application/octet-stream;
    default_type text/plain;
}
D
http {
    include mime.types;
    default_type;
}
Attempts:
2 left
💡 Hint

The order of directives matters and default_type must have a valid value.

Troubleshoot
advanced
2:00remaining
Why is NGINX sending 'Content-Type: text/html' for all files?

An NGINX server is sending Content-Type: text/html for every file, including images and CSS. The config includes include mime.types; and default_type application/octet-stream;. What is the most likely cause?

AThe <code>root</code> directive is missing, causing NGINX to default to <code>text/html</code>.
BThe <code>default_type</code> directive is ignored if <code>include mime.types;</code> is present.
CNGINX caches MIME types and needs a restart to apply changes.
DThe <code>mime.types</code> file is missing or empty, so NGINX falls back to <code>default_type</code> which is overridden elsewhere.
Attempts:
2 left
💡 Hint

Think about what happens if the MIME types file is not loaded properly.

🔀 Workflow
expert
2:00remaining
Order of directives affecting MIME type handling

Consider this NGINX http block:

http {
    default_type application/json;
    include mime.types;
}

What MIME type will NGINX send for a .css file request?

Aapplication/json
Bapplication/octet-stream
Ctext/css
DNo Content-Type header
Attempts:
2 left
💡 Hint

NGINX prioritizes MIME type lookup from the types map (mime.types) before using default_type.