首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在nginx的auth_request模块中使用外部URI

如何在nginx的auth_request模块中使用外部URI
EN

Stack Overflow用户
提问于 2017-02-22 00:12:55
回答 1查看 2.2K关注 0票数 5

我试图以这样的方式使用nginxngx_http_auth_request_module

代码语言:javascript
运行
复制
server {

    location / {
        auth_request http://external.url;
        proxy_pass http://protected.resource;
    }
}

它不起作用,错误是:

代码语言:javascript
运行
复制
2017/02/21 02:45:36 [error] 17917#0: *17 open() "/usr/local/htmlhttp://external.url" failed (2: No such file or directory), ...

或者用这种方式处理named location

代码语言:javascript
运行
复制
server {

    location / {
        auth_request @auth;
        proxy_pass http://protected.resource;
    }

    location @auth {
        proxy_pass http://external.url;
    }
}

在这种情况下,错误几乎是相同的:

代码语言:javascript
运行
复制
2017/02/22 03:13:25 [error] 25476#0: *34 open() "/usr/local/html@auth" failed (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", subrequest: "@auth", host: "127.0.0.1"

我知道有这样一种方法:

代码语言:javascript
运行
复制
server {

    location / {
        auth_request /_auth_check;
        proxy_pass http://protected.resource;
    }

    location /_auth_check {
        internal;
        proxy_pass http://external.url;
    }
}

但是在这种情况下,http://protected.resource不能使用/_auth_check路径。

是否有一种方法可以使用外部URI作为auth_request指令的参数,而不重叠http://protected.resource路由?

如果没有,为什么?

通过静态文件(/usr/local/html)查找auth_request的URI看起来有点奇怪。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-22 08:22:39

有一个鲜为人知的事实是,您不必从/@开始定位。

所以这样做是可行的:

代码语言:javascript
运行
复制
location / {
    auth_request .auth;
    proxy_pass http://protected.resource;
}

location .auth {
    internal;
    proxy_pass http://external.url/auth;
    # you must use path part here ^
    # otherwise it would be invalid request to external.url
}
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42380402

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档