Mastering Nginx

(Ron) #1

A Configuration Guide


[ 34 ]

Besides this usage, default_server may also be helpful in configuring a number


of virtual servers with the same listen directive. Any directives set here will be
the same for all matching server blocks.


Locations – where, when, and how


The location directive may be used within a virtual server section and indicates a
URI that comes either from the client or from an internal redirect. Locations may be


nested with a few exceptions. They are used for processing requests with as specific
a configuration as possible.


A location is defined as follows:


location [modifier] uri {...}

Or for a named location:


location @name {...}

A named location is only reachable from an internal redirect. It preserves the URI


as it was before entering the location block. It may only be defined at the server
context level.


The modifiers affect processing of a location in the following way:


Table: Location modifiers

Modifier Handling
= Use exact match and terminate search.
~ Case-sensitive regular expression matching.
~* Case-insensitive regular expression matching.
^~ Stops processing before regular expressions are
checked for a match of this location's string, if
it's the most specific match. Note that this is not
a regular expression match – its purpose is to
preempt regular expression matching.

When a request comes in, the URI is checked against the most specific location


as follows:



  • Locations without a regular expression are searched for the most-specific
    match, independent of the order in which they are defined.

Free download pdf