systemd and nginx on 13.1

I have nginx installed in /opt/nginx and was installed by Passenger.

I can start it up with

/opt/ngix/sbin/nginx 

and my rails app runs fine.

I created a systemd service and when using that,

systemctl start nginx

hangs forever, but nginx is started.

Trying to access my website results in an error where rails is complaining that it can’t talk to the database, even though the database is running and I can connect and query it. After a few minutes nginx crashes.

[Unit]
Description=HTTP server
After=syslog.target network.target remote-fs.target nss-lookup.target

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

[Install]
WantedBy=multi-user.target

Am I missing something or have something misconfigured here?

The problem is definitely not ngix or my rails app. I can get a rails console and interact with the database.

/opt/nginx/sbin/nginx -t
nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful

I got it worked out.

For any that have a similar issue, I deleted the nginx.service file.

I copied and changed the paths in this file and placed it in /etc/init.d/nginx.

The two lines that I changed were

114: NGINX_BIN=/opt/nginx/sbin/nginx
118: NGINX_PID=/opt/nginx/logs/nginx.pid

Ran these:

chkconfig --set nginx on
systemctl daemon-reload
/etc/init.d/nginx start

And everything is working correctly.

Using systemctl start/stop/status/etc niginx.service works as well.