1

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?

1 Answer 1

0

It's impossible to do on nginx side, because nginx auth_basic_user_file doesn't allow to use variables.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .