我正在尝试以这种方式使用nginx
's ngx_http_auth_request_module
:
server {
location / {
auth_request http://external.url;
proxy_pass http://protected.resource;
}
}
Run Code Online (Sandbox Code Playgroud)
它不起作用,错误是:
2017/02/21 02:45:36 [error] 17917#0: *17 open() "/usr/local/htmlhttp://external.url" failed (2: No such file or directory), ...
Run Code Online (Sandbox Code Playgroud)
或以这种方式与named location
:
server {
location / {
auth_request @auth;
proxy_pass http://protected.resource;
}
location @auth {
proxy_pass http://external.url;
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,错误几乎相同:
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"
Run Code Online (Sandbox Code Playgroud)
我知道有这样的方法:
server {
location / {
auth_request /_auth_check;
proxy_pass http://protected.resource;
}
location /_auth_check {
internal;
proxy_pass http://external.url;
}
}
Run Code Online (Sandbox Code Playgroud)
但是在这种情况下http://protected.resource
不能使用/_auth_check
路径。
有没有办法URI
在auth_request
不重叠http://protected.resource
路由的情况下使用外部作为指令的参数?
如果不是,为什么?通过静态文件 ( )
查找auth_request
的 URI看起来有点奇怪/usr/local/html
。
有一个鲜为人知的事实,您不必以/
或开始位置@
。
所以这会起作用:
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
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1728 次 |
最近记录: |