How to override global auth_basic in nginx How to override global auth_basic in nginx nginx nginx

How to override global auth_basic in nginx


Yes you can do it.

Quoting from the docs: http://nginx.org/en/docs/http/ngx_http_auth_basic_module.html#auth_basic

Syntax: auth_basic string | off;

Default: auth_basic off;

Context: http, server, location, limit_except

As you can see the directive itself can be defined at multiple levels (contexts), i.e. if you have it at global level you can disable it at server or even location level.

The same is true for the auth_basic_user_file directive http://nginx.org/en/docs/http/ngx_http_auth_basic_module.html#auth_basic_user_file

So you can have auth_basic/auth_basic_user_file defined at a global level and have it overridden per individual site

auth.conf:

auth_basic global;                                                          auth_basic_user_file <path_to_your_auth_file>;                  

sitename.conf:

auth_basic sitenamereal; # any name, actually you can omit itauth_basic_user_file <path_to_your_site_specific_file>;