我希望能够将.htpasswd文件放入由nginx提供的文件夹中,以便使nginx使用HTTP auth basic保护相应的location 。
我正在考虑这样的configuration:
server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /var/www; index index.html index.htm; location / { try_files $uri $uri/ =404; } ########################################## ############################# note below location <any folder that contains a .htpasswd file> { auth_basic "Authentication Required"; auth_basic_user_file <respective folder>/.htpasswd; } ############################# note above ########################################## location ~ /\. { deny all; } # disable access to .htpasswd }
我有一个可能的匹配一个文件在其操作系统文件夹中存在的location相当的位置? 是否有可能导出的path,它可以被馈送到auth_basic_user_file ?
如果没有,是否有另外一种方法来实现一个configuration来实现相同的目标?