Recall & Review
beginner
What is the purpose of the
server_name directive in nginx?The
server_name directive tells nginx which domain names or IP addresses a server block should respond to. It helps nginx decide which website to serve based on the requested URL.Click to reveal answer
beginner
How do you specify multiple domain names in the
server_name directive?You list them separated by spaces, like
server_name example.com www.example.com;. Nginx will respond to any of these names in the same server block.Click to reveal answer
intermediate
What happens if no
server_name matches the requested domain?Nginx uses the default server block, usually the first one defined, to respond. This is like a fallback when no specific domain matches.
Click to reveal answer
intermediate
Can
server_name use wildcards? Give an example.Yes, wildcards can be used. For example,
server_name *.example.com; matches any subdomain like blog.example.com or shop.example.com.Click to reveal answer
advanced
What is the difference between
server_name _; and server_name *;?server_name _; is often used as a catch-all default server name. The underscore is a convention and not a wildcard. server_name *; is invalid syntax in nginx.Click to reveal answer
What does the
server_name directive specify in nginx?✗ Incorrect
The
server_name directive tells nginx which domain names to match for this server block.How would you configure nginx to respond to both example.com and www.example.com?
✗ Incorrect
Multiple names are separated by spaces, not commas.
Which of these is a valid wildcard usage in
server_name?✗ Incorrect
Wildcards can only be used at the start or end, like
*.example.com.What happens if no
server_name matches the request?✗ Incorrect
Nginx falls back to the default server block if no names match.
Is
server_name *; a valid nginx configuration?✗ Incorrect
server_name *; is invalid. Use server_name _; for a catch-all name.Explain how the
server_name directive works in nginx and why it is important.Think about how nginx knows which website to show when many domains point to the same server.
You got /5 concepts.
Describe how to configure nginx to serve multiple subdomains using the
server_name directive.Consider how to cover main domain and all subdomains in one server block.
You got /3 concepts.