10

无论如何,我都需要一个表达式来匹配所有请求。

这够好吗?

location ~ ^/

我担心其他位置优先,绕过我的身份验证。

4

1 回答 1

14

您可以将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. 
    }
}
于 2012-08-24T04:57:59.553 回答