nginx fails to start on boot with systemd on Ubuntu 15.04 and 15.10

Solution 1:

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.