无论如何,我都需要一个表达式来匹配所有请求。
这样够好吗?
location ~ ^/
我担心其他位置优先,绕过了我的身份验证。
最佳答案
您可以将ngx_http_auth_basic_module
设置放入以下任意上下文中:
http, server, location, limit_except
您的版本
location ~ ^/
仅当您的
server
部分中没有其他声明的位置时,该方法才有效例子:
server {
... #some server settings
location / { # full equivalent for "~ ^/"
auth_basic on;
auth_basic_user_file /path/to/some/file;
}
location /other_location {
# here http_auth not inherited
}
}
只需将
http_auth
设置放入server
部分中,为此server
描述的所有位置都将继承此设置。例子:
server {
... # some server settings
auth_basic on;
auth_basic_user_file /path/to/some/file;
location / {
# HERE http_auth settings would be
# inherited from previous configuration level.
}
}
关于nginx - 如何匹配Nginx中的所有位置以进行身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12102565/