0
0
Nginxdevops~10 mins

Named locations (@) in Nginx - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Named locations (@)
Client Request Received
Check URI Match
If match normal location
Serve Content
If match named location @name
Internal Redirect to @name
Execute @name block
Serve Content or Further Redirect
When nginx receives a request, it checks if the URI matches a named location starting with '@'. If yes, it internally redirects to that named location block to handle the request.
Execution Sample
Nginx
location / {
    try_files $uri @fallback;
}

location @fallback {
    proxy_pass http://backend;
}
This config tries to serve files normally, but if not found, internally redirects to the named location '@fallback' which proxies to a backend server.
Process Table
StepRequest URICondition CheckedAction TakenResult
1/index.htmlDoes /index.html exist?Yes - serve fileContent served directly
2/missing.htmlDoes /missing.html exist?No - redirect to @fallbackInternal redirect to @fallback
3@fallbackExecute @fallback blockproxy_pass to backendRequest forwarded to backend
4Response from backendReturn responseSend response to clientClient receives backend content
5-No more actionsEnd processingRequest complete
💡 Request completes after serving content or proxying via named location
Status Tracker
VariableStartAfter Step 2After Step 3Final
Request URI/missing.html@fallback@fallbackResponse content
Current Location/@fallback@fallbackDone
Response SourceFile systemN/ABackend serverClient
Key Moments - 3 Insights
Why does nginx use '@' before a location name?
The '@' prefix marks a named location that is not directly accessible by clients but used for internal redirects, as shown in execution_table step 2 and 3.
What happens if the requested file exists?
Nginx serves the file directly without redirecting to the named location, as seen in execution_table step 1.
Can named locations be accessed directly by clients?
No, named locations are internal only and cannot be accessed directly, only via internal redirects like in step 2.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what action does nginx take when /missing.html does not exist?
AServe the file directly
BReturn 404 error
CRedirect internally to @fallback
DProxy to backend without redirect
💡 Hint
See execution_table row 2 where /missing.html triggers internal redirect to @fallback
At which step does nginx proxy the request to the backend server?
AStep 3
BStep 1
CStep 4
DStep 5
💡 Hint
Check execution_table row 3 where @fallback block proxies to backend
If the file /index.html exists, what is the final response source?
ABackend server
BFile system
CNamed location @fallback
D404 error page
💡 Hint
Refer to variable_tracker row 'Response Source' after step 1
Concept Snapshot
Named locations in nginx start with '@' and are used for internal redirects.
They are not accessible directly by clients.
Use them to handle fallback or special routing logic.
Example: try_files $uri @fallback; redirects missing files internally.
Named location blocks can proxy or serve content internally.
This helps organize complex routing cleanly.
Full Transcript
Named locations in nginx are special blocks starting with '@' used for internal redirects. When a client request comes in, nginx checks if the requested URI matches a normal location or if it should internally redirect to a named location. For example, if a requested file does not exist, nginx can redirect internally to a named location like '@fallback' which can proxy the request to a backend server. Named locations cannot be accessed directly by clients; they only serve as internal routing points. This mechanism helps handle fallback scenarios or complex routing in a clean way. The execution table shows step-by-step how nginx processes a request, checks file existence, redirects internally if needed, and finally serves content either from the file system or backend.