View service
First check the service status of nginx, enter systemctl status nginx
, the result is as follows
No related services were found, the next step is to add system services.
Add system service
Add nginx.service
in the /usr/lib/systemd/system
directory, according to Modifications are made based on the actual situation. For detailed analysis, please refer to the article in the reference materials below. The content is as follows
[unit] description=nginx - high performance web server documentation=http://nginx.org/en/docs/ after=network.target remote-fs.target nss-lookup.target [service] type=forking pidfile=/usr/local/nginx/logs/nginx.pid execstartpre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf execstart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf execreload=/bin/kill -s hup $mainpid execstop=/bin/kill -s quit $mainpid privatetmp=true [install] wantedby=multi-user.target
Let’s take a look after adding it
Set up to start automatically at boot
Test it first. Restart and check that the nginx service
is indeed not started. Enter systemctl start nginx
to start
You can use systemctl
to start, indicating the previously added nginx.service
no problem. Then enter systemctl enable nginx
to set up startup
Finally restart and check whether the setting is successful
No problem, now the compilation and installation of nginx is completed, next is the installation of php.
The above is the detailed content of How to add Nginx to system service in CentOS7. For more information, please follow other related articles on the PHP Chinese website!