#1028155 nginx-common: nginx fails to start on reboot when IPv6 enabled.

#1028155#5
Date:
2023-01-07 21:28:36 UTC
From:
To:
Dear Maintainer,

* What led up to the situation?

I have a dual IPv4/IPv6 server with nginx listening on both with the following directive:

server
  {
    server_name "example.org";
    listen 144.202.24.41:443 default_server ssl http2;
    listen [2001:19f0:5401:58:5400:3ff:fe59:e2b1]:443 default_server ssl http2;

    ...
  }

When I reboot the server and login, systemctl report the following:

$ systemctl status nginx.service
× nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Sat 2023-01-07 16:17:40 EST; 50s ago
       Docs: man:nginx(8)
    Process: 481 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
        CPU: 49ms

Jan 07 16:17:40 lj01 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jan 07 16:17:40 lj01 nginx[481]: nginx: [emerg] bind() to [2001:19f0:5401:58:5400:3ff:fe59:e2b1]:443 failed (99: Cannot assign requested address)
Jan 07 16:17:40 lj01 nginx[481]: nginx: configuration file /etc/nginx/nginx.conf test failed
Jan 07 16:17:40 lj01 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Jan 07 16:17:40 lj01 systemd[1]: nginx.service: Failed with result 'exit-code'.
Jan 07 16:17:40 lj01 systemd[1]: Failed to start A high performance web server and a reverse proxy server.

* What exactly did you do (or not do) that was effective (or
   ineffective)?

Restarting the nginx service resolves the issue.

This appears to be a dependency issue in the nginx.service file.

#1028155#10
Date:
2023-01-19 12:11:49 UTC
From:
To:
While nginx has not changed and I have not changed my nginx configuration,
nginx now comes up successfully on reboot.

thanks

#1028155#15
Date:
2023-01-25 11:31:27 UTC
From:
To:
On Thursday, January 19, 2023 7:11:49 AM EST LeJacq, Jean Pierre wrote

This problem reoccurred after updates to my system, none related to nginx.

It appears to be an ordering or race condition in the startup scripts.

thanks

#1028155#20
Date:
2023-03-12 00:51:21 UTC
From:
To:
The core issue is that the nginx is starting before the IPv6 address is bound.

systemd-networkd has a specific service, systemd-networkd-wait-online.service,
that will force all online services to wait until the network interfaces are
configured.

After switching to systemd-networkd from ifupdown, nginx now comes up
reliably.

I'm not sure if this is a bug in nginx. It may be worth an addition to the
documentation about this potential issue.