Skip to content

Instantly share code, notes, and snippets.

@innyso
Created April 26, 2020 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save innyso/7db71b196cf2f87c30da8ec24a34dfb3 to your computer and use it in GitHub Desktop.
Save innyso/7db71b196cf2f87c30da8ec24a34dfb3 to your computer and use it in GitHub Desktop.
#nginx #atsign #namedlocation

Recently I need to do some updating for an nginx configuration, beside the fact that I am a bit rusty with my nginx config skills, I also encounter something like this

location @something {
  # ...
}

Not knowing what this mean, did some quick search and found that this is called a named location and it seems like a good alternative to if-then-else in certain scenario.

For example:

Given the request location is /helloworld, if a file called helloworld exist in the root directory, use it else call a named location with the name something

location @something {
  # ...
}

location /helloworld {
  try_files $uri @something;
}
References

https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms

https://serverfault.com/questions/738452/what-does-the-at-sign-mean-in-nginx-location-blocks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment