Challenge - 5 Problems
Default Server Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What happens when a request matches no server_name?
Given this nginx configuration snippet:
What will be the response body when a request is sent to IP address directly (no Host header or unknown Host)?
server {
listen 80 default_server;
server_name _;
return 200 'Default server response';
}
server {
listen 80;
server_name example.com;
return 200 'Example.com response';
}What will be the response body when a request is sent to IP address directly (no Host header or unknown Host)?
Nginx
server {
listen 80 default_server;
server_name _;
return 200 'Default server response';
}
server {
listen 80;
server_name example.com;
return 200 'Example.com response';
}Attempts:
2 left
💡 Hint
Think about which server block nginx uses when no server_name matches.
✗ Incorrect
Nginx uses the server block marked with 'default_server' for requests that don't match any server_name. Here, the first server block is the default, so it responds with 'Default server response'.
❓ Configuration
intermediate2:00remaining
Identify the correct default server configuration
Which nginx server block configuration correctly sets a default server for HTTP port 80?
Attempts:
2 left
💡 Hint
The 'default_server' keyword must be used with 'listen'.
✗ Incorrect
Only option A uses the correct syntax 'listen 80 default_server;' to mark the server block as default. Other options have invalid syntax or misuse the directive.
❓ Troubleshoot
advanced2:00remaining
Why does nginx serve the wrong server block?
You have two server blocks:
You send a request with Host header 'test.com' but nginx responds with 'Example.com default'. What is the likely cause?
server {
listen 80 default_server;
server_name example.com;
return 200 'Example.com default';
}
server {
listen 80;
server_name test.com;
return 200 'Test.com';
}You send a request with Host header 'test.com' but nginx responds with 'Example.com default'. What is the likely cause?
Attempts:
2 left
💡 Hint
Check if the Host header is correctly sent in the request.
✗ Incorrect
If the Host header is missing or incorrect, nginx cannot match server_name and falls back to the default_server block. This causes the default server block to respond even if another server_name matches.
🔀 Workflow
advanced2:00remaining
Order the steps to set a default server in nginx
Put these steps in the correct order to configure a default server for HTTP requests in nginx:
Attempts:
2 left
💡 Hint
Think about editing config, then reloading, then testing.
✗ Incorrect
First edit the config, then add the default_server directive, reload nginx to apply, and finally test the setup.
✅ Best Practice
expert2:00remaining
Which is the best practice for default server handling in nginx?
Choose the best practice for configuring a default server in nginx to handle unmatched requests safely and clearly.
Attempts:
2 left
💡 Hint
Think about clarity and security for unmatched requests.
✗ Incorrect
Best practice is to explicitly define a default server block with 'default_server' and a generic server_name like '_'. It should return a minimal response like 444 (connection closed) or 404 to avoid leaking information or serving unintended content.