How can I add basic auth to an nginx configuration with rewrite How can I add basic auth to an nginx configuration with rewrite nginx nginx

How can I add basic auth to an nginx configuration with rewrite


It would sound to me like you want to have basic auth enabled for the whole server, and not just a single location. The way locations work, is that only one applies at a time, hence if you specify an auth policy in a single location, but it does a rewrite to some other location, then the other location will not be subject to the auth policy from the previous location

According to the documentation for auth_basic, it seems like it's allowed to be used not just in the location context, but in server and http, too.

Therefore, if you want your whole server to require authentication, simply move all of your auth_basic directives up one level, from being in a single location, to being in a single server.