start nginx on boot with systemd

You seem to confuse enable, start and mask operations.

  • systemctl start, systemctl stop: starts (stops) the unit in question immediately;
  • systemctl enable, systemctl disable: marks (unmarks) the unit for autostart at boot time (in a unit-specific manner, described in its [Install] section);
  • systemctl mask, systemctl unmask: disallows (allows) all and any attempts to start the unit in question (either manually or as a dependency of any other unit, including the dependencies of the default boot target). Note that marking for autostart in systemd is implemented by adding an artificial dependency from the default boot target to the unit in question, so "mask" also disallows autostarting.

So, these all are distinct operations. Of these, you want systemctl enable.

Ref.: systemctl(1).

More: Lennart Poettering (2011-03-02). "The Three Levels of Off". systemd for Administrators. 0pointer.de.


Fixed the link in the accepted answer so it redirects to the right page. But here's a relevant bit:

sudo systemctl enable nginx.service
sudo systemctl start nginx.service
sudo systemctl status nginx.service

where /lib/systemd/system/nginx.service looks something like:

# Stop dance for nginx
# =======================
#
# ExecStop sends SIGSTOP (graceful stop) to the nginx process.
# If, after 5s (--retry QUIT/5) nginx is still running, systemd takes control
# and sends SIGTERM (fast shutdown) to the main process.
# After another 5s (TimeoutStopSec=5), and if nginx is alive, systemd sends
# SIGKILL to all the remaining processes in the process group (KillMode=mixed).
#
# nginx signals reference doc:
# http://nginx.org/en/docs/control.html
#
[Unit]
Description=A high performance web server and a reverse proxy server
After=network.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
TimeoutStopSec=5
KillMode=mixed

[Install]
WantedBy=multi-user.target

`

Heres what worked for me: https://web.archive.org/web/20150328063215/https://longhandpixels.net/blog/2014/02/install-nginx-debian-ubuntu

I ignored most of the document, which was specific to compiling other versions, of nginx, and went over to "Make it Autostart".

I followed the directions there, and now when I reboot, nginx 1.9 is running.

I definately appreciate everyone's help, and insight. Thank you all!