Skip to content

nginx config validation fails when using hostname in proxypass or upstreams #207409

Open

Description

@symphorien
diff --git a/nixos/tests/nginx.nix b/nixos/tests/nginx.nix
index 73f1133bd6c..b1010ac1f7d 100644
--- a/nixos/tests/nginx.nix
+++ b/nixos/tests/nginx.nix
@@ -30,6 +30,7 @@ import ./make-test-python.nix ({ pkgs, ... }: {
         extraConfig = ''
           access_log syslog:server=unix:/dev/log,facility=user,tag=mytag,severity=info ceeformat;
           location /favicon.ico { allow all; access_log off; log_not_found off; }
+          location / { proxy_pass https://foo.bar.com:443; }
         '';
       };
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.

Originally posted by @delroth in #205561 (comment)

Activity

  1. 62 remaining items

  2. added
    0.kind: bug
    on May 13, 2024
  3. RafaelKr commented on Oct 21, 2024

    @RafaelKr
    Contributor

    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).

    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.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 (

    after = [ "network.target" ] ++ map (certName: "acme-selfsigned-${certName}.service") dependentCertNames;
    ) 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.

  4. added
    2.status: stale
    on Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bug2.status: stale

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions