0

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?

  • I don't think keepalive is available with `proxy_pass` plain URLs. Have you tried to use the variables in `upstream` block `server` directives? – Tero Kilkanen Oct 04 '22 at 21:31
  • @TeroKilkanen this doesn't work, NGINX isnt starting saying "invalid port" and "host not found" – DoktorMerlin Oct 05 '22 at 07:49

0 Answers0