5

nginx will not start on boot, but starts fine manually. The logs say something like

nginx: [emerg] host not found in upstream "{some hostname}" in /etc/nginx/conf.d/some_site.conf
nginx: configuration file /etc/nginx/nginx.conf test failed

Failed to start A high performance web server and a reverse proxy server.
nginx.service: Unit entered failed state.
nginx.service: Failed with result 'exit-code'.

It seems that on bootup dns is not ready yet and nginx is trying to lookup a hostname that I have in as a reverse proxy.

Paul
  • 271

1 Answers1

9

After some research it turns out systemd uses the file below to startup nginx

/lib/systemd/system/nginx.service

The file on Ubuntu 15.04, Ubuntu 15.10, and even the nginx site itself say to use the After line like below

After=network.target

This makes a person think that the network should up and ready to go. However, I found the link http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/ that says

network.target has very little meaning during start-up. It only indicates that the network management stack is up after it has been reached.

The link goes on to say

network-online.target is a target that actively waits until the nework is "up", where the definition of "up" is defined by the network management software.

So I changed the After use that instead like

After=network-online.target

Now nginx starts up fine on bootup. I am not claiming this is the fully correct solution as it is possible that a different After target should be used that would be more correct in some other way, but this seems to work for the last couple of reboots.

Paul
  • 271