如何匹配nginx中的所有位置,用于身份验证?

前端之家收集整理的这篇文章主要介绍了如何匹配nginx中的所有位置,用于身份验证?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

这够好吗?

location ~ ^/

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

您可以将ngx_http_auth_basic_module设置放入以下任何上下文中:

http,server,location,limit_except

你的版本

location ~ ^/

仅当您的服务器部分中没有其他声明的位置时才会起作用
例:

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 {
    ... # 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. 
    }
}
原文链接:https://www.f2er.com/nginx/434985.html

猜你在找的Nginx相关文章