The recommended way to add Nginx to systemd is via the following from https://www.nginx.com/resources/wiki/start/topics/examples/systemd/:

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

However, if you’re using Phusion Passenger also and run the command sudo passenger-status, you may get the following error message:

ERROR: Phusion Passenger doesn't seem to be running. If you are sure that it is running, then the causes of this problem could be:

1. You customized the instance registry directory using Apache's PassengerInstanceRegistryDir option, Nginx's passenger_instance_registry_dir option, or Phusion Passenger Standalone's --instance-registry-dir command line argument. If so, please set the environment variable PASSENGER_INSTANCE_REGISTRY_DIR to that directory and run passenger-status again.
2. The instance directory has been removed by an operating system background service. Please set a different instance registry directory using Apache's PassengerInstanceRegistryDir option, Nginx's passenger_instance_registry_dir option, or Phusion Passenger Standalone's --instance-registry-dir command line argument.

This is because Phusion Passenger utilizes the /tmp directory, which has been modified via the systemd line above that reads PrivateTmp=true. So if you want Phusion Passenger to run without any problems, you’ll want to change PrivateTmp=true to PrivateTmp=false.

The correct systemd code for using Phusion Passenger with Nginx (and the default /opt/nginx path from the Phusion Passenger install) is:

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/opt/nginx/logs/nginx.pid
ExecStartPre=/opt/nginx/sbin/nginx -t
ExecStart=/opt/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=false

[Install]
WantedBy=multi-user.target



Update

Alternatively, as noted by Hongli Lai (the creator of Phusion Passenger) in the comments below, you can use the Phusion Passenger directive passenger_instance_registry_dir . For example, you can add the following line to your Nginx configuration file’s http block (assuming you’ve installed Nginx at /opt/nginx):

passenger_instance_registry_dir /opt/nginx/tmp;

You’ll first have to create the directory if it doesn’t exist (sudo mkdir /opt/nginx/tmp), and then specify the environment variable when running sudo passenger-status, for example:

PASSENGER_INSTANCE_REGISTRY_DIR=/opt/nginx/tmp sudo -E passenger-status