2017-02-22 67 views
1

我试图用nginxngx_http_auth_request_module以这样的方式:我如何使用外部URI与nginx的的auth_request模块

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; 
    } 
} 

在这种情况下,错误是阿尔莫ST相同:

2017/02/22 03:13:25 [error] 25476#0: *34 open() "/usr/local/[email protected]" 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看起来有点奇怪。

回答

1

有一个鲜为人知的事实是,你不必与/@开始位置。

所以这会工作:

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 
} 
+0

非常感谢您!我无法在文档中找到它,它在那里吗? –

+0

它不存在,但是也不需要以'/'开头的前缀。 –