configurationnginx使用可选的.htpasswd

Hello Serverfault成员。

我想让我的NginX使用一个可选的.htpasswd文件。 原因是,我的configurationdynamic服务于webcontent。 基于$ http_host。

所以我已经尝试了以下内容:

if (-f "/foo/$http_host/.htpasswd") { auth_basic "Restricted"; auth_basic_user_file "/foo/$http_host/.htpasswd"; } 

但是这不起作用,因为auth_basic不允许在一个if里面。 如果我只使用两个auth_basic行,它会显示一个没有.htpasswd的web内容403。

有没有可能做到这一点,而不使用一个单独的configuration文件的保护内容?

在nginx方面是不可能的,因为nginx auth_basic_user_file不允许使用variables。