njs and subrequests

Antoine Bonavita antoine.bonavita at gmail.com
Wed Nov 21 19:37:52 UTC 2018


Hello Dmitry,

Thanks for your answer. I understand locations can be configured to proxy
to external locations and therefore be used in subrequests from njs. That
is what I am doing for now. I consider this to be a workaround. Before I
explain why, I should explain the basics of my pet project. You can think
of it as a service to which you post the URL of an RSS feed and I expect
the server to retrieve the feed, collect all the articles in parallel
(using subrequests) and concatenating the result in my response.
Therefore, the URLs I need to query are not known in advance. And, if I am
not mistaken, that forces me to use a variable as argument for my
proxy_pass, just like I mentioned in my first email:
    location = /fwd-proxy {
        proxy_pass $arg_tgt;
    }
Because of that, my understanding is that the external requests are
performed using HTTP/1.0 and in particular the connection(s) to the
external sources are not kept alive, making the initiator "pay" for the TCP
connection establishment on every single request. Am I mistaken in my
understanding ?

Of course, all this is fine as long as I play in my sandbox and with
servers that I can reach with low latency, but I'm concerned if this
becomes an actual service one day.

Thanks for your precious help,

Antoine.

On Mon, Nov 19, 2018 at 2:28 PM Dmitry Volyntsev <xeioex at nginx.com> wrote:

>
> Hi Antoine,
>
>  >Is there any plan to have subrequest from ngx_http_js_module support
>  > external URLs ?
>
> Nothing prevents you from making subrequests to external URLs.
>
> https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
> https://nginx.org/en/docs/http/ngx_http_core_module.html#resolver
>
>  >The address can be specified as a domain name or IP address
> ..
>  >In this case, if an address is specified as a domain name, the name is
> searched among the described server groups, and, if not found, is
> determined using a resolver.
>
> You still need a location to make a proxy_pass for you (what you already
> have).
>
> As Valentine said, there is nothing special in ngx_http_js_module about
> subrequests. The module simply uses internal NGINX API for subrequests
> (http://hg.nginx.org/njs/file/tip/nginx/ngx_http_js_module.c#l2099).
>
> You, can find a more complex example of using njs subrequests here:
> https://github.com/nginxinc/nginx-openid-connect
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20181121/093df504/attachment.html>


More information about the nginx mailing list