I have an nginx configured to dynamically proxy to another network, say ourdomain.com/legacy/otherdomain/443/examplepath?examplearg=examplevalue
will be mapped to otherdomain.legacydomain.com:443/examplepath?examplearg=examplevalue
and ourdomain.com/legacy/yetanotherdomain/123/
will be mapped to yetanotherdomain.legacydomain.com:123/
. With this configuration I dynamically proxy into our old VPN and it works great for the most part. It's configured like proxy_pass https://$legacy_subdomain.legacydomain.com:$new_port/$new_path$is_args$args
However, nginx is closing connections for each request which for some third party servers results in huge losses of performance. Sites that need 3 seconds to load without the nginx need 30 seconds with nginx. The problem of course is that Nginx is not keeping the connection alive.
Now I only found out the possibility to add keepalives when using upstream blocks. However, due to the dynamic nature of my Nginx configuration this is not possible in my case as I would have to configure upstream blocks for an unknown number of devices and domains. Is there any way to configure Nginx so that it can keep connections alive without using upstream blocks?