Workaround of race condition between systemd and nginx.

Gena Makhomed gmm at csdoc.com
Wed Dec 30 18:53:57 UTC 2015


On 30.12.2015 20:28, Daniel K. wrote:

>> nginx now requires configured and up network, before starting daemon.
>> Replace network.target with network-online.target is easy workaround.
>
> Actually it does not require that at all.

nginx failed to start if network is down via systemd race condition.

> It would be more helpful if you posted your config files, but from your
> log file i gather they look something like:
>
> server {
> 	listen	172.22.22.202:80;
> 	[...]
> }

this is allowed syntax:

http://nginx.org/en/docs/http/ngx_http_core_module.html#listen

> And that, due to using systemd, the nginx service gets started before
> the network-interface have been configured with the IP address shown.

Yes. And nginx failed to start with *correct* config.

> Two ways you can work around this issue comes to mind.
>
> 1) Allow non-local binds
>
> # echo 1 > /proc/sys/net/ipv4/ip_nonlocal_bind
>
> Put 'net.ipv4.ip_nonlocal_bind = 1' in /etc/sysctl.conf to make it stick.
>
>
> 2) Configure nginx to listen to *:80
>
> Add this to your config files somewhere.
>
> server {
> 	listen	80;
> }
>
> to your config files somewhere, and nginx will listen to 0.0.0.0:80
> instead of every IP address you mention.
>
>
> Hope that helps,

And I should send this text fragment to all nginx users?

or this text fragment should be included in manual

http://nginx.org/en/docs/http/ngx_http_core_module.html#listen

?

or (better way) workaround should just be included in nginx unit file?

-- 
Best regards,
  Gena



More information about the nginx-devel mailing list