location regex

Francis Daly francis at daoine.org
Thu Nov 3 18:53:12 UTC 2016

On Tue, Nov 01, 2016 at 06:49:04PM -0400, olat wrote:

Hi there,

> I am asking about regex in the context of caching some
> of the requests on front-end proxy to speed up django app loading dynamic
> content where session is involved. Does it mean each of the filtered out
> requests we would like to cache, should duplicate the same location block? 

I think that a lot of this configuration will naturally inherit into
a location{} block, so you could potentially set the common pieces at
server{} level and just have the small number repeated in the individual

Or you could generate the nginx.conf fragment with lots of duplicate
content; you would only have a single source in your generator to change.

Or you could have the common config in an external file and "include"
it multiple times.

In general, you write the config a few times, and nginx reads it many
times. So it is often worth making it easy for nginx to reads, even at
the expense of making it harder for you to write.

>     # catch only /appfoo* and /appbar*
>     location ~ /app(foo|bar)* {

Another feature of regexen is that it is not always obvious what they
should do. For example, "/foo/app" and "/appbaz" will both match this

(Effectively, the above is "does the request include the four-character
string /app anywhere?", which is not what the comment suggests that
you wanted.)

Francis Daly        francis at daoine.org

More information about the nginx mailing list