Home > Operation and Maintenance > Nginx > How to add Nginx to system service in CentOS7

How to add Nginx to system service in CentOS7

PHPz
Release: 2023-05-13 14:49:06
forward
1193 people have browsed it

View service

First check the service status of nginx, enter systemctl status nginx, the result is as follows

How to add Nginx to system service in CentOS7

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
Copy after login

Let’s take a look after adding it

How to add Nginx to system service in CentOS7

Set up to start automatically at boot

Test it first. Restart and check that the nginx service

How to add Nginx to system service in CentOS7

is indeed not started. Enter systemctl start nginx to start

How to add Nginx to system service in CentOS7

You can use systemctl to start, indicating the previously added nginx.service no problem. Then enter systemctl enable nginx to set up startup

How to add Nginx to system service in CentOS7

Finally restart and check whether the setting is successful

How to add Nginx to system service in CentOS7

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template