You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
nginx config validation fails when using hostname in proxypass or upstreams #207409
0.kind: bugSomething is broken2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md
nginx config validation failed.
config was /nix/store/mkhs81aygpwhhc44q6iispfy9lvsdswa-nginx.conf.
in case of false positive, set `services.nginx.validateConfig` to false.
nginx output:
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (2: No such file or directory)
2022/12/22 22:07:17 [emerg] 7#7: host not found in upstream "foo.bar.com" in /build/conf:44
nginx: configuration file /build/conf test failed
I've disabled the config validation for my machine config for now, but I don't have a strong opinion on how important this regression is -- the module maintainers might.
I'm deploying my config via deploy-rs. I also have configured a proxy_pass with a hostname. On some deployments it fails with the same reason: host not found in upstream "example.com" in /etc/nginx/nginx.conf:190 (I have services.nginx.enableReload configured, this is why it's pointing to /etc/nginx/nginx.conf).
But the root cause is still related to the way how nix restarts the services.
It's only happening when some other services than nginx are restarted. Here's the (shortened) list of services which are stopped which cause a deployment failure: stopping the following units: acme-fixperms.service, acme-lockfiles.service, audit.service, kmod-static-nodes.service, [...] network-local-commands.service, nscd.service, [...] systemd-modules-load.service, systemd-networkd-wait-online.service, systemd-networkd.service, systemd-networkd.socket, systemd-oomd.service, systemd-oomd.socket, systemd-resolved.service, systemd-sysctl.service, systemd-timedated.service, systemd-timesyncd.service, systemd-tmpfiles-resetup.service, systemd-udevd-control.socket, systemd-udevd-kernel.socket, systemd-udevd.service, systemd-vconsole-setup.service
Probably it's related to one of those: systemd-networkd-wait-online.service, systemd-networkd.service, systemd-networkd.socket, systemd-resolved.service.
So the solution would be a multi-phase restart. First, services related to networking should be fully restarted, then the services depending on them (nginx in my case).
Maybe we can add another service dependency in the systemd service. As there already is a dependency on network.target (
) maybe we also need to also add network-online.target or something related to systemd-resolved by default. Or maybe the dependency must be set with requires instead of after but I'm not experienced enough with systemd configuration to make an educated suggestion.
Of course this should be configurable because maybe there is a use case where nginx should run without a network/dns-resolver available.
But I think the new dependency should be configured by default as I now had more than one outage caused by this.
0.kind: bugSomething is broken2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md
Activity
nixos/nginx: add regression test for NixOS#207409
62 remaining items
RafaelKr commentedon Oct 21, 2024
I'm deploying my config via
deploy-rs. I also have configured aproxy_passwith a hostname. On some deployments it fails with the same reason:host not found in upstream "example.com" in /etc/nginx/nginx.conf:190(I haveservices.nginx.enableReloadconfigured, this is why it's pointing to/etc/nginx/nginx.conf).The reason is that nginx checks the hostname during the startup phase. Sometimes on deployment some services which are required to resolve the hostname are stopped while nginx config is checked.
I found the reason and a workaround described in this article: https://sandro-keil.de/blog/let-nginx-start-if-upstream-host-is-unavailable-or-down/
But the root cause is still related to the way how nix restarts the services.
It's only happening when some other services than nginx are restarted. Here's the (shortened) list of services which are stopped which cause a deployment failure:
stopping the following units: acme-fixperms.service, acme-lockfiles.service, audit.service, kmod-static-nodes.service, [...] network-local-commands.service, nscd.service, [...] systemd-modules-load.service, systemd-networkd-wait-online.service, systemd-networkd.service, systemd-networkd.socket, systemd-oomd.service, systemd-oomd.socket, systemd-resolved.service, systemd-sysctl.service, systemd-timedated.service, systemd-timesyncd.service, systemd-tmpfiles-resetup.service, systemd-udevd-control.socket, systemd-udevd-kernel.socket, systemd-udevd.service, systemd-vconsole-setup.serviceProbably it's related to one of those:
systemd-networkd-wait-online.service, systemd-networkd.service, systemd-networkd.socket, systemd-resolved.service.So the solution would be a multi-phase restart. First, services related to networking should be fully restarted, then the services depending on them (nginx in my case).
Maybe we can add another service dependency in the systemd service. As there already is a dependency on
network.target(nixpkgs/nixos/modules/services/web-servers/nginx/default.nix
Line 1247 in ed0aa37
network-online.targetor something related tosystemd-resolvedby default. Or maybe the dependency must be set withrequiresinstead ofafterbut I'm not experienced enough with systemd configuration to make an educated suggestion.Of course this should be configurable because maybe there is a use case where nginx should run without a network/dns-resolver available.
But I think the new dependency should be configured by default as I now had more than one outage caused by this.