简体   繁体   English

如何将结果 api 响应用于 proxy_pass 属性

[英]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.

相关问题 如何使用proxy_pass重写URI nginx反向代理? - How to rewrite URI nginx reverse proxy using proxy_pass? 如何提取嵌入标签的src attribut - How can i extract src attribut of embed tag 如何在不同的 BrowserView 对象中使用不同的用户:通过经过身份验证的代理? - How can I use a different user:pass authenticated proxy in different BrowserView objects? 我如何将 api 响应存储在变量中并将其传递给反应弹出视频播放器 - How can i store api response in variable and pass it to react popup video player 使Socket.io路径与NGiNX proxy_pass一起使用 - Making Socket.io path work with NGiNX proxy_pass 使用proxy_pass将NGINX链接到Node.js集群 - Linking NGINX to Node.js Cluster using proxy_pass NGINX proxy_pass http://localhost:9999/ 未找到 - NGINX proxy_pass http://localhost:9999/ Not Found 当我有更多具有相同ID的内容时,如何在ID属性中添加数字表示? - How can i add increament of number in an Id attribut when i have more content with same Id? 如何在属性上添加“ id” <img> 当我单击图像时? - How can i add attribut “id” on <img> when i click the image? 如何将API响应存储到对象中,以便以后在脚本中使用它? - How do store API response into object so I can use it later in script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM