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. } }
source share