At my web hosting company, in the past months we’ve started using CentOS 7 for brand new dedicated servers, and we also started migrating old CentOS 6.x machines to the latest version of CentOS.
One of the big changes introduced in CentOS 7 is systemd, this changes everything we all knew about system services inside Linux as stated in my previous post CentOS 7 vs CentOS 6.
This Nginx Systemd Service file should work on Fedora, CentOS and RHEL withut any problems.
Create the Nginx systemd service file:
nano -w /lib/systemd/system/nginx.service
Copy and paste this text inside:
[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
This nginx systemd service file is useful when you compile Nginx manually without using any binary RPMs.