Auth_request understanding

Can anyone explain the flow of a request with auth_request? If auth_request passes it goes to localhost:9000 and if it fails goes to localhost:8000.

There are location blocks in the 3 server blocks. If auth_request passes does it use the location blocks from the main server block or localhost:9000? And if it fails does it use the location blocks from the main server block or localhost:8000?

location / {
  auth_request /authrequest;
  error_page 401 = @failed;
  proxy_pass http://localhost:9000;
}

location @failed {
  proxy_pass http://localhost:8000;
}

Your assertion is correct.

If auth_request succeeds, then processing continues in the same location block.
If it fails, then the error is handled per the configuration, in this case, processing moves to the @failed named location.

If you’re seeing strange results then please share more of the configuration. log_subrequest on; can help with troubleshooting.