0
0
Nginxdevops~5 mins

Default server handling in Nginx - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Aserver_default
Bdefault_server
Cdefault_block
Dserver_main
What happens if no 'default_server' is set and a request does not match any server_name?
ANginx returns an error
BNginx ignores the request
CNginx uses the first server block for that port
DNginx redirects to a default page
How do you set a server block as default for HTTPS on port 443?
Alisten 443;
Bserver_name default 443;
Cdefault_server 443;
Dlisten 443 default_server;
Can you have two server blocks with 'default_server' on the same port?
ANo, nginx will fail to start
BYes, nginx will load balance
CYes, but only one will respond
DNo, but nginx will ignore one
What does nginx use to match incoming requests to server blocks?
AIP, port, and server_name
BPort only
CIP address only
Dserver_name only
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.