0
0
Nginxdevops~20 mins

Location blocks in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nginx Location Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of Nginx location block matching
Given the following Nginx configuration snippet, what will be the response for a request to /images/logo.png?
Nginx
server {
    location /images/logo.png {
        return 200 'Logo image';
    }
    location /images/ {
        return 200 'Images folder';
    }
}
A404 Not Found
BLogo image
CImages folder
D500 Internal Server Error
Attempts:
2 left
💡 Hint
Nginx chooses the most specific matching location block.
🧠 Conceptual
intermediate
2:00remaining
Understanding prefix and regex location blocks
Which location block will handle a request to /api/v1/users given this configuration?
Nginx
location /api/ {
    return 200 'API prefix';
}
location ~ ^/api/v1/ {
    return 200 'API v1 regex';
}
ABoth handle it simultaneously
BNeither handles it, 404 returned
CThe regex location ~ ^/api/v1/ handles it
DThe prefix location /api/ handles it
Attempts:
2 left
💡 Hint
Regex locations have higher priority if they match.
Troubleshoot
advanced
2:00remaining
Why does this location block not serve static files?
You have this Nginx config but requests to /static/css/style.css return 404. What is the likely cause?
Nginx
location /static/ {
    root /var/www/html;
}
AThe root directive should be alias instead
BThe root directive is correct; problem is file permissions
CThe root path is incorrect, should be /var/www/html/static
DThe location block should use alias /var/www/html/static/;
Attempts:
2 left
💡 Hint
Understand how root and alias work with location paths.
🔀 Workflow
advanced
2:00remaining
Order of location block evaluation
Arrange the steps Nginx follows to select a location block for a request.
A1,2,3,4
B2,1,3,4
C3,2,1,4
D1,3,2,4
Attempts:
2 left
💡 Hint
Exact matches have highest priority.
Best Practice
expert
2:00remaining
Best practice for combining prefix and regex locations
Which configuration best ensures that requests to /app/ use a prefix location but requests to /app/api/ use a regex location?
Alocation /app/ { ... } location ~ ^/app/api/ { ... }
Blocation ~ ^/app/ { ... } location /app/api/ { ... }
Clocation /app/api/ { ... } location ~ ^/app/ { ... }
Dlocation ~ ^/app/api/ { ... } location /app/ { ... }
Attempts:
2 left
💡 Hint
Regex locations override prefix locations if they match.