Challenge - 5 Problems
API Routing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the response for a request to /api/v1/users?
Given the following nginx configuration, what will be the response status code when a client requests
/api/v1/users?Nginx
server {
listen 80;
location /api/ {
return 200 "API root";
}
location /api/v1/ {
return 404;
}
}Attempts:
2 left
💡 Hint
Nginx chooses the most specific matching location block.
✗ Incorrect
The request path /api/v1/users matches both /api/ and /api/v1/ location blocks. Nginx selects the longest prefix match, which is /api/v1/. This block returns 404.
❓ Configuration
intermediate2:00remaining
Which location block correctly proxies /api/v2/ requests?
You want to proxy all requests starting with
/api/v2/ to http://backend:8080. Which location block configuration achieves this correctly?Attempts:
2 left
💡 Hint
Trailing slash in proxy_pass affects URI rewriting.
✗ Incorrect
Using
proxy_pass http://backend:8080/; inside a prefix location with trailing slash rewrites the URI correctly by replacing the matching part. Option B is correct to proxy /api/v2/ requests properly.❓ Troubleshoot
advanced2:30remaining
Why does /api/v1/data return 404 despite correct backend?
Given this nginx config, requests to
/api/v1/data return 404. What is the likely cause?Nginx
server {
listen 80;
location /api/ {
proxy_pass http://backend:8080/api/;
}
location /api/v1/ {
proxy_pass http://backend:8080/v1/;
}
}Attempts:
2 left
💡 Hint
Check how proxy_pass rewrites the URI with trailing slashes.
✗ Incorrect
The /api/v1/ location proxies to http://backend:8080/v1/, but the request URI /api/v1/data is appended, resulting in http://backend:8080/v1/data. However, the backend expects /v1/data without the /api/v1 prefix. The mismatch causes 404.
🔀 Workflow
advanced3:00remaining
Order the steps to add a new API version routing in nginx
Arrange the steps to add routing for
/api/v3/ that proxies to http://backend:9090/v3/.Attempts:
2 left
💡 Hint
You must reload nginx before testing changes.
✗ Incorrect
First add the location block (1), then configure proxy_pass (3), reload nginx to apply (2), and finally test the routing (4).
✅ Best Practice
expert3:00remaining
Which configuration best avoids overlapping location conflicts?
You have multiple API versions: /api/v1/, /api/v2/, and a generic /api/. Which nginx config best avoids conflicts and ensures correct routing?
Attempts:
2 left
💡 Hint
Use ^~ to prioritize prefix matches over regex or generic locations.
✗ Incorrect
Using
^~ tells nginx to stop searching when a prefix match is found, avoiding conflicts between /api/v1/, /api/v2/, and /api/. This ensures specific versions route correctly before the generic /api/.