0
0
Nginxdevops~5 mins

server_name directive in Nginx - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AThe IP address of the server
BThe domain names the server block responds to
CThe port number to listen on
DThe root directory of the website
How would you configure nginx to respond to both example.com and www.example.com?
Aserver_name www.example.com.example.com;
Bserver_name example.com, www.example.com;
Cserver_name example.com; server_name www.example.com;
Dserver_name example.com www.example.com;
Which of these is a valid wildcard usage in server_name?
Aserver_name *.example.com;
Bserver_name example.*;
Cserver_name example.com*;
Dserver_name *example.com;
What happens if no server_name matches the request?
ANginx redirects to google.com
BNginx returns a 404 error
CNginx uses the default server block
DNginx shuts down
Is server_name *; a valid nginx configuration?
ANo, it is invalid syntax
BYes, but only for IP addresses
CYes, it matches all domains
DYes, but only for localhost
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.