Skip to content

Instantly share code, notes, and snippets.

@scottalan
Last active July 26, 2016 15:03
Show Gist options
  • Save scottalan/9405dd5335a7397ec5c3c161b60dceb6 to your computer and use it in GitHub Desktop.
Save scottalan/9405dd5335a7397ec5c3c161b60dceb6 to your computer and use it in GitHub Desktop.
Nginx - Location blocks

// This will match /my-path, /my-path/other/path/index.php, /my-path/index.html

location /my-path {
    . . .
}

// Exact path matching.

location = /my-path {
    . . .
}

// Prevent regular expression matching from occurring if it is determined to be the best non-regular expression match.

location ^~ /my-path {
    . . .
}
(none): If no modifiers are present, the location is interpreted as a prefix match. This means that the location given will be matched against the beginning of the request URI to determine a match.
=: If an equal sign is used, this block will be considered a match if the request URI exactly matches the location given.
~: If a tilde modifier is present, this location will be interpreted as a case-sensitive regular expression match.
~*: If a tilde and asterisk modifier is used, the location block will be interpreted as a case-insensitive regular expression match.
^~: If a carat and tilde modifier is present, and if this block is selected as the best non-regular expression match, regular expression matching will not take place.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment