Skip to content

Instantly share code, notes, and snippets.

@pricees
Created August 8, 2012 21:23
Show Gist options
  • Save pricees/3298890 to your computer and use it in GitHub Desktop.
Save pricees/3298890 to your computer and use it in GitHub Desktop.
A small note about nginx locations
http://wiki.nginx.org/NginxHttpCoreModule#location
Example:
location = / {
# matches the query / only.
[ configuration A ]
}
location / {
# matches any query, since all queries begin with /, but regular
# expressions and any longer conventional blocks will be
# matched first.
[ configuration B ]
}
location ^~ /images/ {
# matches any query beginning with /images/ and halts searching,
# so regular expressions will not be checked.
[ configuration C ]
}
location ~* \.(gif|jpg|jpeg)$ {
# matches any request ending in gif, jpg, or jpeg. However, all
# requests to the /images/ directory will be handled by
# Configuration C.
[ configuration D ]
}
Example requests:
/ -> configuration A
/documents/document.html -> configuration B
/images/1.gif -> configuration C
/documents/1.jpg -> configuration D
Note that you could define these 4 configurations in any order and the results would remain the same.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment