How to add Nginx to system services in CentOS7

How to add Nginx to system services in CentOS7

Introduction

After compiling, installing and solving the problem, Nginx is running normally, but Nginx is not added to the system service at this time. Next, we will add Nginx to the system services and set it to start at boot.

View Services

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

No related services are found, the next step is to add system services.

Adding system services

Add nginx.service in the /usr/lib/systemd/system directory and modify it according to the actual situation. For detailed analysis, please refer to the article in the reference 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

After adding, check again

Set automatic startup

First test it, restart it and then check the Nginx service

It really didn't start. Enter systemctl start nginx to start

You can use systemctl to start it, which means there is no problem with nginx.service added previously. Then enter systemctl enable nginx to set it to start at boot

Finally restart to check whether the setting is successful

No problem, the compilation and installation of Nginx is complete, and the next step is to install PHP.

Reference: CentOS 7 systemd adds custom system services,

You may also be interested in:
  • How to install PHP7.4 and Nginx on Centos
  • Detailed tutorial for installing nginx on centos8 (picture and text)
  • CentOS 7.2 builds nginx web server to deploy uniapp project
  • Solve the problem of "Welcome to nginx on Fedora!" after installing nginx on Centos7, and there is no default.conf file in the conf.d directory
  • Centos7.3 How to install and deploy Nginx and configure https
  • How to install Nginx in CentOS7 and configure automatic startup
  • Centos7 startup process and Nginx startup configuration in Systemd
  • How to build a private server in docker (docker-registry with nginx&ssl on centos)
  • Detailed explanation of the implementation process of Nginx log timing splitting in CentOS 7

<<:  Solution to the problem that the MySQL database cannot be accessed by other IP addresses

>>:  How to use CocosCreator for sound processing in game development

Recommend

How to smoothly upgrade nginx after compiling and installing nginx

After nginx is compiled and installed and used fo...

Introduction to the use of http-equiv attribute in meta tag

meta is an auxiliary tag in the head area of ​​htm...

Detailed explanation of map overlay in openlayers6

1. Overlay Overview Overlay means covering, as th...

jQuery implements a simple comment area

This article shares the specific code of jQuery t...

JavaScript to achieve simple drag effect

This article shares the specific code of JavaScri...

8 essential JavaScript code snippets for your project

Table of contents 1. Get the file extension 2. Co...

How to find the specified content of a large file in Linux

Think big and small, then redirect. Sometimes Lin...

How to encapsulate query components based on element-ui step by step

Table of contents Function Basic query functions ...

Sample code for implementing dark mode with CSS variables

Recently, WeChat was forced by Apple to develop a...

Detailed installation tutorial of Mysql5.7.19 under Centos7

1. Download Download mysql-5.7.19-linux-glibc2.12...

Vue implements the magnifying glass effect of tab switching

This article example shares the specific code of ...

Linux RabbitMQ cluster construction process diagram

1. Overall steps At the beginning, we introduced ...