0
0
Nginxdevops~20 mins

server_name directive in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Server Name Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding the purpose of the server_name directive

What is the main role of the server_name directive in an Nginx server block?

AIt sets the root directory for serving static files.
BIt defines the port number on which Nginx listens for incoming connections.
CIt specifies the domain names or IP addresses that the server block should respond to.
DIt configures the SSL certificate paths for HTTPS connections.
Attempts:
2 left
💡 Hint

Think about how Nginx decides which server block handles a request based on the requested domain.

💻 Command Output
intermediate
1:30remaining
Output of Nginx server block with multiple server_name values

Given this Nginx server block snippet:

server {
    listen 80;
    server_name example.com www.example.com api.example.com;
    return 200 'Hello from example.com!';
}

What will be the response when a user visits http://api.example.com?

AHello from example.com!
B404 Not Found
C502 Bad Gateway
DDefault Nginx welcome page
Attempts:
2 left
💡 Hint

Check which server_name matches the requested domain.

Configuration
advanced
2:00remaining
Correctly configuring server_name for wildcard subdomains

Which server_name directive correctly matches all subdomains of example.com except the root domain itself?

Aserver_name *example.com;
Bserver_name example.com*;
Cserver_name example.com.*;
Dserver_name *.example.com;
Attempts:
2 left
💡 Hint

Remember how wildcards work in domain matching for Nginx.

Troubleshoot
advanced
2:00remaining
Troubleshooting server_name mismatch causing 404 errors

An Nginx server block has server_name www.example.com; but requests to example.com return 404 errors. What is the most likely cause?

AThe listen directive is missing the port number.
BThe server_name does not include <code>example.com</code>, so Nginx does not match the request to this block.
CThe root directive is incorrectly set.
DNginx does not support multiple server_name values.
Attempts:
2 left
💡 Hint

Check if the requested domain is listed in server_name.

🔀 Workflow
expert
2:30remaining
Order of server_name matching in Nginx

Given these server blocks, which server block will handle a request to test.example.com?

server {
    listen 80;
    server_name example.com;
    return 200 'Root domain';
}

server {
    listen 80;
    server_name *.example.com;
    return 200 'Wildcard subdomain';
}

server {
    listen 80;
    server_name test.example.com;
    return 200 'Specific subdomain';
}
AThe block with server_name test.example.com
BThe block with server_name example.com
CThe first server block defined in the config
DThe block with server_name *.example.com
Attempts:
2 left
💡 Hint

Check how Nginx prioritizes exact names over wildcards.