0
0
Nginxdevops~5 mins

Named locations (@) in Nginx - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a named location in nginx and how is it defined?
A named location in nginx is a special internal location block identified by an '@' prefix. It is defined using location @name { ... } and is used for internal redirects within the server configuration.
Click to reveal answer
beginner
How do you perform an internal redirect to a named location in nginx?
You use the try_files directive or the error_page directive with a URI starting with '@'. For example, try_files $uri @fallback; redirects internally to the named location @fallback if the file is not found.
Click to reveal answer
intermediate
Why would you use named locations in nginx instead of regular locations?
Named locations are used for internal redirects only and are not accessible directly by clients. They help organize complex routing logic, such as fallback handling or error processing, without exposing these paths externally.
Click to reveal answer
beginner
Can a named location be accessed directly by a client request?
No, named locations cannot be accessed directly by clients. They are internal and only reachable through internal redirects configured in nginx.
Click to reveal answer
intermediate
Show an example of a named location used for fallback in nginx.
Example:<br>
location / {
  try_files $uri $uri/ @fallback;
}

location @fallback {
  proxy_pass http://backend;
}
<br>This tries to serve the file, and if not found, internally redirects to @fallback which proxies the request.
Click to reveal answer
What prefix is used to define a named location in nginx?
A@
B#
C$
D%
Can clients directly access a named location URL in nginx?
AYes, always
BOnly with special headers
COnly if explicitly allowed
DNo, named locations are internal only
Which directive is commonly used to redirect to a named location if a file is not found?
Atry_files
Brewrite
Cproxy_pass
Dlisten
What is the main purpose of using named locations in nginx?
ATo serve static files
BTo enable SSL
CTo create internal redirects for complex routing
DTo define server ports
Which of the following is a valid named location block in nginx?
Alocation /@fallback { }
Blocation @fallback { }
Clocation fallback@ { }
Dlocation fallback { }
Explain what named locations (@) are in nginx and why they are useful.
Think about how nginx handles internal routing and fallback.
You got /5 concepts.
    Describe how to configure nginx to use a named location for fallback when a requested file is missing.
    Focus on the try_files syntax and named location block.
    You got /4 concepts.