Hello Serverfault members.
I want my NginX to use an optional .htpasswd file. The reason is, that my config dynamically serves the webcontent. Based on $http_host.
So I've tried the following:
if (-f "/foo/$http_host/.htpasswd") {
auth_basic "Restricted";
auth_basic_user_file "/foo/$http_host/.htpasswd";
}
But this does not work because auth_basic
is not allowed inside an if
.
If I only use the two auth_basic lines it shows me a 403 for webcontent without .htpasswd.
Is there a possibility to achieve this without using a seperate config file for the protected contents?