0
0
Nginxdevops~20 mins

Directives and blocks in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nginx Blocks Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of nginx configuration test with nested blocks
Given the following nginx configuration snippet, what will be the output of nginx -t command?
Nginx
http {
    server {
        listen 80;
        location / {
            root /var/www/html;
        }
    }
    location /images/ {
        root /var/www/images;
    }
}
A
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
B
nginx: [warn] duplicate location "/images/" in /etc/nginx/nginx.conf:8
nginx: configuration file /etc/nginx/nginx.conf test failed
C
nginx: [emerg] unknown directive "location" in /etc/nginx/nginx.conf:6
nginx: configuration file /etc/nginx/nginx.conf test failed
D
nginx: [emerg] "location" directive is not allowed here in /etc/nginx/nginx.conf:8
nginx: configuration file /etc/nginx/nginx.conf test failed
Attempts:
2 left
💡 Hint
Check where location blocks are allowed inside nginx configuration.
🧠 Conceptual
intermediate
1:30remaining
Understanding directive context in nginx
Which of the following directives can only be used inside a server block and not directly inside the http block?
Ainclude
Blisten
Clog_format
Dworker_processes
Attempts:
2 left
💡 Hint
Think about where nginx listens for connections.
Troubleshoot
advanced
2:30remaining
Troubleshooting nginx block nesting error
You added this snippet to your nginx config but get an error on reload. What is the cause?
Nginx
server {
    listen 443 ssl;
    ssl_certificate /etc/ssl/cert.pem;
    ssl_certificate_key /etc/ssl/key.pem;
    server_name example.com;
    http {
        location / {
            proxy_pass http://localhost:3000;
        }
    }
}
AThe <code>http</code> block cannot be nested inside a <code>server</code> block.
BThe <code>ssl_certificate</code> directive is misplaced and should be inside <code>location</code>.
CThe <code>proxy_pass</code> directive must be outside any block.
DThe <code>server_name</code> directive is missing a semicolon.
Attempts:
2 left
💡 Hint
Check nginx block hierarchy rules.
🔀 Workflow
advanced
2:00remaining
Order of nginx configuration blocks for a basic web server
What is the correct order of nginx configuration blocks from top-level to nested for a basic HTTP server?
A2,3,1,4
B3,2,1,4
C2,1,3,4
D1,3,2,4
Attempts:
2 left
💡 Hint
Think about the main blocks and their nesting levels.
Best Practice
expert
3:00remaining
Best practice for organizing nginx directives and blocks
Which practice is best for organizing nginx configuration files to improve maintainability and clarity?
APlace all directives inside the main <code>nginx.conf</code> file without includes.
BAvoid using <code>include</code> directives to prevent confusion.
CUse multiple <code>server</code> blocks inside <code>http</code> and split configuration into separate files included with <code>include</code> directive.
DPut <code>location</code> blocks directly inside the <code>http</code> block for simplicity.
Attempts:
2 left
💡 Hint
Think about modularity and ease of updates.