Understanding Nginx location rules

Ningx is slim and the configuration feels in many respects less bloated than Apache. But it’s also a little idiosyncratic, and the official documentation, still, is not great. I keep forgetting about the location rules, so here’s an attempt to make my own cheatsheet.

A location block applies some configuraton by matching against a request URI. A location can be one of these five types:

 nginx

(The official documentation, among other things, calls “prefix” the type identifier string ( =,^*,~,~*); this can be confusing, because we are also speaking (in cases 2.a 2.b) of “prefix matching” …)

Important: among the list of location blocks inside a server, only one will be picked (or none). The only way to “compose” settings is by using nested locations.

One thought on “Understanding Nginx location rules

  1. FeelPlanet

    Although this is a general rule that will allow you to design your location blocks in a predictable way, it is important to realize that there are times when a new location search is triggered by certain directives within the selected location. The exceptions to the “only one location block” rule may have implications on how the request is actually served and may not align with the expectations you had when designing your location blocks.

    Reply

Leave a Reply to FeelPlanet Cancel reply

Your email address will not be published. Required fields are marked *