Bug 1397812 - nginx fails to start on boot when set to bind to an address
Summary: nginx fails to start on boot when set to bind to an address
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: systemd
Version: 24
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: systemd-maint
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-11-23 11:59 UTC by Bruno Larini
Modified: 2016-11-23 15:53 UTC (History)
9 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-11-23 15:53:35 UTC
Type: Bug


Attachments (Terms of Use)

Description Bruno Larini 2016-11-23 11:59:08 UTC
Description of problem:
nginx/1.10.2 fails to start on boot when configured to bind to a specific network interface, configured with NetworkManager.

Version-Release number of selected component (if applicable):
nginx-1.10.2-1.fc24.x86_64
systemd-229-16.fc24.x86_64
NetworkManager-1.2.4-3.fc24.x86_64

Steps to Reproduce:
1. Install nginx from the official repository
2. Change the config file to bind to a specific interface (listen xxx.xxx.xxx.xxx;)
3. Set to nginx to start on boot (systemctl enable nginx.service)
4. Reboot the computer

Actual results:
nginx service not running.

Expected results:
nginx service running after reboot.

Additional info:
Even the previous version had this problem, but I manually changed the Unit section in systemd from this:

    After=network.target remote-fs.target nss-lookup.target

to this:

    After=network-online.target

and it solved the issue. After the last update the systemd config file was replaced, so I had to change it again.

The following is the message from the error to bind to the interface:

22:00 nginx.service: Failed with result 'exit-code'. systemd
22:00 nginx.service: Unit entered failed state. systemd
22:00 Failed to start The nginx HTTP and reverse proxy server. systemd
22:00 nginx.service: Control process exited, code=exited status=1 systemd
22:00 nginx: configuration file /etc/nginx/nginx.conf test failed nginx
22:00 nginx: [emerg] bind() to xxx.xxx.xxx.xxx:80 failed (99: Cannot assign requested address) nginx

Comment 1 Zbigniew Jędrzejewski-Szmek 2016-11-23 15:53:35 UTC
Yes, binding to a specific IP address requires that address to be available. For a system socket unit, you should set FreeBind=yes (https://www.freedesktop.org/software/systemd/man/systemd.socket.html#FreeBind=) . I don't know how to set this in the nginx config.

You shouldn't modify packaged unit files in /usr/lib/systemd. Create a drop-in in /etc/. See https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Description.


Note You need to log in before you can comment on or make changes to this bug.