Nginx cannot bind static IPv6 address on boot
Bug #1818574 reported by
Vihai
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
nginx (Debian) |
Fix Released
|
Unknown
|
|||
nginx (Ubuntu) |
Won't Fix
|
Low
|
Unassigned |
Bug Description
Hello,
I have a Ubuntu cosmic box with static IPv4 and IPv6 addresses. It noticed that on boot nginx is not able to bind to the explicit IPv6 address. However, trying few seconds after boot completed it starts fine.
Mar 04 21:02:10 gems systemd[1]: Starting A high performance web server and a reverse proxy server...
Mar 04 21:02:10 gems nginx[640]: nginx: [emerg] bind() to [2a09:62c0:
Mar 04 21:02:10 gems nginx[640]: nginx: configuration file /etc/nginx/
The network is configured with systemd-networkd and netplan.io
Apparently nginx is started before the network is fully stable.
Changed in nginx (Debian): | |
status: | Unknown → New |
Changed in nginx (Ubuntu): | |
status: | Triaged → Won't Fix |
Changed in nginx (Debian): | |
status: | New → Fix Released |
To post a comment you must log in.
Thanks for filing this bug in Ubuntu.
There are similar cases out there with other services, when a specific IP address is selected for the service to bind to. openssh, for example, has this bug upstream: https:/ /bugzilla. mindrot. org/show_ bug.cgi? id=2512
A few solutions, or workarounds, exist for this. The only one that seems to work for all use cases is to use the IP_FREEBIND socket option:
described below.
IP_FREEBIND (since Linux 2.4)
If enabled, this boolean option allows binding to an IP address that is nonlocal or does not (yet) exist. This permits listening on a socket, without requiring the underlying network inter‐
face or the specified dynamic IP address to be up at the time that the application is trying to bind to it. This option is the per-socket equivalent of the ip_nonlocal_bind /proc interface
That requires an upstream change, however.
In the meantime, users affected by this are probably better off by having nginx starting later in the boot process by adding a dependency to network- online. target. It will likely make the boot slower, though, that's why it's not a good solution to be applied generally.
You can try this perhaps:
sudo systemctl edit nginx.service
Then in the empty file that opens, type: online. target network- online. target
[Unit]
After=network-
Requires=
Then save. You can view your addition in the output of this command now:
sudo systemctl cat nginx.service
There appear to be more fine-grained ways of achieving this, like specifying which interface to wait for. https:/ /www.freedeskto p.org/software/ systemd/ man/systemd- networkd- wait-online. html documents something like that, but I haven't tried it.