I use nginx to proxy and hold persistent connections to far away servers for me.
I have configured about 15 blocks similar to this example:
upstream rinu-test {
server test.rinu.test:443;
keepalive 20;
}
server {
listen 80;
server_name test.rinu.test;
location / {
proxy_pass https://rinu-test;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $http_host;
}
}
The problem is, if the hostname cannot be resolved in one or more of the upstream
blocks, nginx will not (re)start. I can't use static IPs either, some of these hosts explicitly said not to do that because IPs will change. Every other solution I've seen to this error message says to get rid of upstream
and do everything in the location
block. That is not possible here because keepalive
is only available under upstream
.
I can temporarily afford to lose one server but not all 15.
Edit: Turns out nginx is not suitable for this use case. An alternative backend (upstream) keepalive proxy should be used. A custom Node.js alternative is in my answer. So far, I haven't found any other alternatives that actually work.
proxy_pass https://rinu-test;
toproxy_pass $proxyurl;
and before that you can set the variableset $proxyurl $scheme://$host$request_uri
And next is to try use variable in upstream, I have not tested the 2nd option and can't verify yet. But using a variable inproxy_pass
disables dns caching in nginx – Shantayproxy_pass https://rinu-test$request_uri;
– Shantay