Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.