FIX: Ngnix fails to start if upstream host for stream is unavailable/unreachable
Issue:
Currently, if the upstream host being forwarded to is down, Nginx fails to start. Reported by @StefaBa here: https://github.com/NginxProxyManager/nginx-proxy-manager/pull/2672#issuecomment-1475361687
Impact:
In this scenario:
- All other hosts managed by NPM are now also taken out.
- NPM cannot be started in order to disable or edit the host configuration in order to rectify the issue.
Solution:
Declare a variable for forwarding_host instead of simply injecting it directly into the proxy_pass directive.
Use variables for proxy_pass directive in order to prevent startup failure if the upstream host is down.
@StefaBa this one is for you. I think it should work, but I don't use this functionality, so can you please test it?
FYI: There are actually only a couple of functionally changed lines. Most of the change is indentation which I added to make the code easier for me to read.
npm still fails to start, here's a pastebin of the startup log: https://pastebin.com/XW8z4GLK
fwiw: newhost.wan.vm is currently not only offline, but also unknown to the local DNS server. -> nslookup newhost.wan.vm currently yields:
** server can't find newhost.wan.vm: NXDOMAIN
with newhost.wan.vm being offline, but known to the local DNS server NPM does come online (both with the current :latest version and with :github-pr-2714)
Can you share what 3.conf looks like?
here you go: https://pastebin.com/eufsKe7W
i since tried recreating this stream in :github-pr-2714, but that always shows the stream as "Offline" in the web-ui, even when newhost.wan.vm is online.
edit: the pastebin is the original 3.conf, generated by :latest recreating the stream in :latest and then using it in :github-pr-2714 shows the stream as "Online" in both :latest and :github-pr-2714. (as long as newhost.wan.vm is online)
Sorry, I should have been more specific - I wanted to see 3.conf generated by :github-pr-2714 to make sure I didn't screw something up. I think it should look something like this:
# ------------------------------------------------------------
# 40173 TCP: 0 UDP: 1
# ------------------------------------------------------------
set $forwarding_host newhost.wan.vm;
set $forwarding_port 40173;
server {
listen 40173 udp;
#listen [::]:40173 udp;
proxy_pass $forwarding_host:$forwarding_port;
# Custom
include /data/nginx/custom/server_stream[.]conf;
include /data/nginx/custom/server_stream_udp[.]conf;
}
It's possible that I should have included the set declarations inside the server block (I'm not super hot on Nginx variable scoping), but I think it should work as it is.
PR is now considered stale. If you want to keep it open, please comment :+1:
CI Error:
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
certbot-node: Pulling from nginxproxymanager/nginx-full
Digest: sha256:eaa2ebcb50dd87557c9a8f95a3230128d94cac1ea17800261c036e59378e7d49
Status: Image is up to date for nginxproxymanager/nginx-full:certbot-node
docker.io/nginxproxymanager/nginx-full:certbot-node
[1;34m❯ [1;36mBuilding Frontend ...[0m
yarn install v1.22.22
[1/4] Resolving packages...
[2/4] Fetching packages...
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
error Command failed.
Exit code: 128
Command: git
Arguments: clone https://github.com/tabler/tabler.git /usr/local/share/.cache/yarn/v6/.tmp/e11a93799a52aa978c82015e29fbe309
Directory: /app/frontend
Output:
Cloning into '/usr/local/share/.cache/yarn/v6/.tmp/e11a93799a52aa978c82015e29fbe309'...
error: RPC failed; curl 92 HTTP/2 stream 5 was not closed cleanly: CANCEL (err 8)
error: 512 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
PR is now considered stale. If you want to keep it open, please comment :+1: