systemd and nginx on 13.1

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

I can start it up with


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.

Description=HTTP server

ExecStartPre=/opt/nginx/sbin/nginx -t
ExecReload=/bin/kill -s HUD $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID


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/

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.