Challenge - 5 Problems
Named Locations Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
What is the output status code when accessing /test?
Given the following nginx configuration, what HTTP status code will the client receive when requesting
/test?Nginx
server {
listen 80;
location /test {
return 302 @redirect;
}
location @redirect {
return 404;
}
}Attempts:
2 left
💡 Hint
Look at what the named location @redirect returns.
✗ Incorrect
The /test location returns a 302 redirect to the named location @redirect. The @redirect location returns a 404 status, so the client ultimately receives 404 Not Found.
❓ Configuration
intermediate2:00remaining
Which configuration correctly uses a named location to serve a maintenance page?
Select the nginx configuration snippet that correctly uses a named location
@maintenance to serve a static maintenance page when /maintenance is requested.Attempts:
2 left
💡 Hint
Named locations are used with return or error_page directives, not proxy_pass.
✗ Incorrect
Option B correctly uses return 302 to redirect to the named location @maintenance, which serves the static file. Proxy_pass cannot target named locations, and rewrite with break does not invoke named locations.
❓ Troubleshoot
advanced2:00remaining
Why does the named location @error not get triggered?
Given this nginx config, why does the named location
@error never get used when a 500 error occurs?
server {
listen 80;
location / {
proxy_pass http://backend;
error_page 500 @error;
}
location @error {
return 503 'Service temporarily unavailable';
}
}Attempts:
2 left
💡 Hint
Check the backend server response and error_page usage.
✗ Incorrect
Named locations can be used with error_page inside location blocks. The return directive is valid. If the backend never returns 500, the named location @error won't be triggered.
🔀 Workflow
advanced2:00remaining
What is the sequence of location processing when using named locations?
Consider this nginx configuration:
location /start {
return 302 @next;
}
location @next {
proxy_pass http://backend;
}
What is the correct sequence of processing when a client requests /start?Attempts:
2 left
💡 Hint
Named locations starting with @ are internal and cannot be requested directly by clients.
✗ Incorrect
The return 302 @next sends a redirect response to the client. The client then makes a new request to the URI '@next', which is invalid as a URI, so this is a misconfiguration. However, nginx treats the @next as a named location internally only if used with internal redirects, not with return 302. So the client receives a redirect to '@next' which is invalid. Thus, option A is the closest correct sequence, but in practice this config causes client error.
✅ Best Practice
expert2:30remaining
Which is the best way to use named locations for internal rewrites without client redirects?
You want to internally rewrite requests to
/oldpath to a named location @newpath without telling the client to redirect. Which configuration snippet achieves this correctly?Attempts:
2 left
💡 Hint
Use error_page with a custom code to trigger internal named location rewrites.
✗ Incorrect
Option D uses a custom error code 418 to trigger an internal redirect to the named location @newpath without client involvement. Option D sends a client redirect which exposes the named location. Option D rewrites to /newpath which is not a named location. Option D tries to proxy_pass to a named location which is invalid.