0
0
Nginxdevops~20 mins

Server block structure in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nginx Server Block Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of nginx -t with this server block?
Given this nginx server block configuration, what will be the output of nginx -t?
Nginx
server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/example;
    index index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
}
A
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Bnginx: [emerg] unknown directive "server_name" in /etc/nginx/nginx.conf:3
Cnginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignored
Dnginx: [error] open() "/var/www/example/index.html" failed (2: No such file or directory)
Attempts:
2 left
💡 Hint
Check if the syntax of the server block is correct and all directives are valid.
🧠 Conceptual
intermediate
1:00remaining
Which directive defines the domain names served by this server block?
In an nginx server block, which directive specifies the domain names that the server responds to?
Alisten
Bserver_name
Croot
Dindex
Attempts:
2 left
💡 Hint
Think about which directive tells nginx which website names to match.
Configuration
advanced
2:00remaining
Identify the error in this server block configuration
What error will nginx report when testing this server block configuration?
Nginx
server {
    listen 80
    server_name example.com;
    root /var/www/html;
}
Anginx: [error] invalid parameter "80" in /etc/nginx/nginx.conf:2
B
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Cnginx: [warn] server_name directive is deprecated in /etc/nginx/nginx.conf:3
Dnginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/nginx.conf:2
Attempts:
2 left
💡 Hint
Check for missing semicolons in the configuration.
Troubleshoot
advanced
2:00remaining
Why does nginx serve the default site instead of your custom server block?
You created a server block for example.com but nginx serves the default site instead. What is the most likely cause?
AThe root directory does not contain an index.html file
BThe location block is missing a try_files directive
CThe server_name directive is missing or does not match the requested domain
DThe listen directive is set to port 443 but you are accessing via HTTP
Attempts:
2 left
💡 Hint
Check if nginx knows which server block matches the domain you requested.
🔀 Workflow
expert
3:00remaining
Order the steps to enable a new nginx server block and activate it
Put these steps in the correct order to enable a new nginx server block and make it active.
A1,2,3,4
B1,3,2,4
C3,1,2,4
D2,1,3,4
Attempts:
2 left
💡 Hint
Think about creating config, testing it, enabling it, then reloading nginx.