Damn you nginx...

Let's say you have a simple location directive like:

location / {
auth_reques /auth;
index index.html;

location = /auth {
proxy_pass <...>;

Now guess how often nginx makes a subrequest to /auth.

Thats correct TWO times... "why?" you ask?

Well isn't it obvious that nginx hits the auth request, then rewrites the request to the index file, hits the auth request again because it's technically a different request now and then proceeds to hand out the file?

Thanks for documenting this. NOT

  • 5
    This is documented behaviour.
  • 1
    Hint: Move the second location block to be above the first.
  • 2
    @kescherRant does not matter if the auth location in on top because the auth route is most specific route and nginx will not try the other one.
  • 3
    @kescherRant out of nginx docs:

    nginx first searches for the most specific prefix location given by literal strings regardless of the listed order. In the configuration above the only prefix location is “/” and since it matches any request it will be used as a last resort. Then nginx checks locations given by regular expression in the order listed in the configuration file.
  • 1
    @fuckwit Oh, guess I was wrong then
  • 1
    @kescherRant happens. I had the same idea at first and later read that this did not matter for me
Add Comment