I have a situation wherein we have set auth_basic
in global level for all non live sites. Is it possible in Nginx to override this auth_basic
in site specific file and apply auth_basic
for site-specific path with new authentication password.
auth_basic
in global level is set on /etc/nginx/conf.d/auth.conf
site-specific configuration lies on /etc/nginx/sites-enabled/sitename.conf
in nginx.conf I have:
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
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 it
auth_basic_user_file <path_to_your_site_specific_file>;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With