Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to control NGINX 'Location' directive matching order?
    primarykey
    data
    text
    <p>I'm trying to optimize my 'location' directives and cannot find a good way of determining if a specific location match is even attempted. Using <code>echo</code> inside the location block doesn't help here.</p> <p><a href="http://wiki.nginx.org/HttpCoreModule#location" rel="nofollow noreferrer">The NGINX ngx_http_core_module documentation</a> is somewhat confusing.</p> <p>To use regular expressions, you must use a prefix:</p> <ol> <li><p><code>~</code> For case sensitive matching</p></li> <li><p><code>~*</code> For case insensitive matching</p></li> </ol> <p>How the match is performed:</p> <ol> <li><p>Directives with the <code>=</code> prefix that match the query exactly. If found, searching stops.</p></li> <li><p>All remaining directives with conventional strings. If this match used the <code>^~</code> prefix, searching stops.</p></li> <li><p>Regular expressions, in the order they are defined in the configuration file.</p></li> <li><p>If #3 yielded a match, that result is used. Otherwise, the match from #2 is used.</p></li> </ol> <p>Number 2 here says "conventional strings" but then says it can be used with the <code>^~</code> prefix. Doesn't <code>~</code> imply a RegExp? If not, how does it determine what is an isn't a RegExp?</p> <p>Specifically, I want the following:</p> <ol> <li><p>Serve anything out of literal <code>/assets</code> directly. STOP SEARCH.</p></li> <li><p>Serve anything matching RegExp <code>\.php$|/$</code> via fast-CGI STOP SEARCH.</p></li> <li><p>Serve everything else directly via literal <code>/</code></p></li> </ol> <p>This way, there is only a <code>/</code> match attempt for non-dynamic files served from outside of assets.</p> <p>I have:</p> <pre><code>location ^~ /assets {} # search-terminating literal? or regex? location ~ \.php$|/$ {} location / {} # is this match always attempted? </code></pre> <p>From the document, it looks as though the actual order would be 1-3-2, always running the literal <code>/</code> match. Yes, this optimization won't make any difference for real performance, but I just want to clear up some ambiguity.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload