0
0
Nginxdevops~20 mins

Contexts (main, events, http, server, location) in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nginx Context Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Identify the correct context for worker_connections
In which Nginx configuration context should the directive worker_connections be placed to properly set the maximum number of simultaneous connections per worker process?
Alocation
Bhttp
Cserver
Devents
Attempts:
2 left
💡 Hint
Think about where Nginx manages connection handling globally.
💻 Command Output
intermediate
2:00remaining
Output of nginx -T with misplaced location block
What error message will Nginx produce if a location block is placed directly inside the main context (outside http) and you run nginx -T to test the configuration?
Nginx
location /test {
    proxy_pass http://localhost:8080;
}
Anginx: configuration file /etc/nginx/nginx.conf test is successful
Bnginx: [emerg] "location" directive is not allowed here in /etc/nginx/nginx.conf:2
Cnginx: [warn] unknown directive "location" in /etc/nginx/nginx.conf:2
Dnginx: [error] invalid parameter in location block in /etc/nginx/nginx.conf:2
Attempts:
2 left
💡 Hint
Consider which contexts allow location blocks.
🔀 Workflow
advanced
2:30remaining
Order of contexts for serving a request
Arrange the Nginx configuration contexts in the order they are processed when serving an HTTP request.
A2,1,3,4,5
B1,3,2,4,5
C1,2,3,4,5
D1,3,4,5,2
Attempts:
2 left
💡 Hint
Think about the global setup, connection handling, HTTP processing, and request routing.
Troubleshoot
advanced
2:00remaining
Why is proxy_pass ignored in main context?
You added the directive proxy_pass http://backend; directly inside the http context, but it has no effect on requests. Why?
A<code>proxy_pass</code> must be inside a <code>location</code> block, not directly in <code>http</code>
B<code>proxy_pass</code> is deprecated and ignored in all contexts
C<code>proxy_pass</code> only works inside <code>server</code> blocks, not <code>http</code>
D<code>proxy_pass</code> requires the <code>events</code> context to be enabled
Attempts:
2 left
💡 Hint
Where do you usually put routing rules?
Best Practice
expert
2:30remaining
Best context for gzip compression directives
Where should you place gzip compression directives like gzip on; and gzip_types for best practice and efficient configuration?
AInside the <code>http</code> context to apply globally to all servers
BInside each <code>server</code> block to customize per domain
CInside the <code>location</code> blocks to control compression per URI
DInside the <code>events</code> context because it handles connections
Attempts:
2 left
💡 Hint
Compression usually applies to all HTTP responses unless you want exceptions.