How to map all locations in nginx, for auth?

I need an expression to match all requests, no matter what.

Is this enough?

location ~ ^/ 

I am worried that other places take precedence, bypassing my auth.

+6
source share
1 answer

You can set the ngx_http_auth_basic_module parameters in any of the following contexts:

 http, server, location, limit_except 

Your version

 location ~ ^/ 

It will work only if you do not have other declared locations in the server section Example:

 server { ... #some server settings location / { # full equivalent for "~ ^/" auth_basic on; auth_basic_user_file /path/to/some/file; } location /other_location { # here http_auth not inherited } } 

Just put the http_auth settings in the server section, and all the locations described for this server will inherit these settings.
Example:

 server { ... # some server settings auth_basic on; auth_basic_user_file /path/to/some/file; location / { # HERE http_auth settings would be # inherited from previous configuration level. } } 
+8
source

Source: https://habr.com/ru/post/923612/


All Articles