我试图以这样的方式使用nginx的ngx_http_auth_request_module:
server {
location / {
auth_request http://external.url;
proxy_pass http://protected.resource;
}
}它不起作用,错误是:
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
server {
location / {
auth_request @auth;
proxy_pass http://protected.resource;
}
location @auth {
proxy_pass http://external.url;
}
}在这种情况下,错误几乎是相同的:
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"我知道有这样一种方法:
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看起来有点奇怪。
发布于 2017-02-22 08:22:39
有一个鲜为人知的事实是,您不必从/或@开始定位。
所以这样做是可行的:
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
}https://stackoverflow.com/questions/42380402
复制相似问题