Challenge - 5 Problems
Nginx Location Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2: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';
}
}Attempts:
2 left
💡 Hint
Nginx chooses the most specific matching location block.
✗ Incorrect
The location /images/logo.png is more specific than /images/, so it handles the request and returns 'Logo image'.
🧠 Conceptual
intermediate2: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';
}Attempts:
2 left
💡 Hint
Regex locations have higher priority if they match.
✗ Incorrect
Nginx first checks prefix locations, then regex locations. If a regex matches, it takes precedence over prefix matches.
❓ Troubleshoot
advanced2: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;
}Attempts:
2 left
💡 Hint
Understand how root and alias work with location paths.
✗ Incorrect
Using root with /static/ appends the full request URI after root, causing path mismatch. alias replaces the location prefix with the given path.
🔀 Workflow
advanced2:00remaining
Order of location block evaluation
Arrange the steps Nginx follows to select a location block for a request.
Attempts:
2 left
💡 Hint
Exact matches have highest priority.
✗ Incorrect
Nginx first looks for exact matches, then prefix matches, then regex matches, and finally selects the best match.
✅ Best Practice
expert2: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?Attempts:
2 left
💡 Hint
Regex locations override prefix locations if they match.
✗ Incorrect
Defining the prefix location first and then the regex location for the subpath ensures correct matching and priority.