Recall & Review
beginner
What is the purpose of the 'default_server' directive in nginx?
The 'default_server' directive marks a server block as the default to handle requests that do not match any other server_name. It ensures nginx knows which server block to use when no specific match is found.
Click to reveal answer
beginner
How do you specify a default server for HTTP traffic in nginx?
You add 'default_server' to the listen directive, for example: listen 80 default_server; This tells nginx to use this server block as the default for port 80.
Click to reveal answer
intermediate
What happens if no default_server is set in nginx and a request does not match any server_name?
Nginx will use the first server block defined for that listen port as the default. This can lead to unexpected behavior if you don't explicitly set a default server.
Click to reveal answer
intermediate
Can you have multiple default servers for the same port in nginx?
No, only one server block per listen port can be marked as 'default_server'. Trying to set multiple default servers for the same port will cause nginx to fail to start.
Click to reveal answer
intermediate
How does nginx decide which server block to use when a request comes in?
Nginx first matches the request's IP and port to a listen directive. Then it matches the Host header to server_name. If no match, it uses the default_server for that listen port.
Click to reveal answer
Which directive marks a server block as the default in nginx?
✗ Incorrect
The 'default_server' directive is used in the listen directive to mark a server block as the default.
What happens if no 'default_server' is set and a request does not match any server_name?
✗ Incorrect
Nginx uses the first server block defined for the listen port as the default if no 'default_server' is set.
How do you set a server block as default for HTTPS on port 443?
✗ Incorrect
You add 'default_server' to the listen directive like 'listen 443 default_server;' to set it as default for HTTPS.
Can you have two server blocks with 'default_server' on the same port?
✗ Incorrect
Only one server block per port can be 'default_server'. Multiple defaults cause nginx startup failure.
What does nginx use to match incoming requests to server blocks?
✗ Incorrect
Nginx matches requests by IP and port (listen directive) and then by server_name.
Explain how nginx decides which server block handles a request when multiple server blocks exist.
Think about the order nginx uses to find the right server block.
You got /3 concepts.
Describe how to configure a default server in nginx and why it is important.
Focus on the 'listen' directive and request routing.
You got /3 concepts.