[英]How can I use the result api response to the proxy_pass attribut
My client come with an encrypted URI on the nginx server.我的客户端在 nginx 服务器上带有加密的 URI。 NGINX have to decrypt it by sending a request to an API.
NGINX 必须通过向 API 发送请求来解密它。 The result of this API call is the URI decrypted that is use to be the proxy URI.
此 API 调用的结果是解密后用作代理 URI 的 URI。
I've use NJS pluging for NGINX to make the API call, but I catch this error "async operation inside "redirect_uri" variable handler"我已经使用 NJS 插件为 NGINX 进行 API 调用,但我发现了这个错误“在“redirect_uri”变量处理程序中的异步操作”
http{
js_set $redirect_uri redirect_uri;
server {
location ~ ^/upload/(.*)$ {
proxy_request_buffering off;
resolver 127.0.0.1 ipv6=off;
proxy_pass '$redirect_uri';
}
}
}
function redirect_uri(r) {
r.uri.replace("/upload/", "");
r.subrequest('/api/decrypt-uri/'+hash, { method: 'POST' }, function(res) {
if (res.status != 200) {
r.return(res.status);
return;
}
var data=res.responseBody.toString();
return data;
});
}```
2019/07/30 15:55:07 [error] 10667#10667: *1 async operation inside "redirect_uri" variable handler, client: 127.0.0.1, server: api, request: "POST /upload/aHR0cHM6Ly9rbm94LmJpZ2RhdGEuaW5mcmEuZGdmaXAvZ2F0ZXdheS9kZWZhdWx0L3dlYmhkZnybXF5OHYtMDdWeFVaQ1JheFFTRTMxeTJ2Z0hhOHFmV002WkhsRzItQWtRLXVRd2ZvblZpX2lyMDlxZU9IZUtMWHdyejdNTnFJeEdMdFZqSk0= HTTP/1.1"
This looks similar to a question asked here: https://github.com/nginx/njs/issues/213 , with the answer:这看起来类似于这里提出的问题: https : //github.com/nginx/njs/issues/213 ,答案是:
r.subrequest() (or any async functions like setTimeout()) is not supported inside js_set variables handler.
js_set 变量处理程序不支持 r.subrequest()(或任何异步函数,如 setTimeout())。 you need to use auth_request directive.
您需要使用 auth_request 指令。 See a related example .
请参阅相关示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.