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

Why the disk space is not released after deleting data in MySQL

Table of contents Problem Description Solution Pr...

Detailed explanation of how to use element-plus in Vue3

Table of contents 1. Installation 2. Import in ma...

Using CSS3 to achieve transition and animation effects

Why should we use CSS animation to replace JS ani...

Summary of Vue's monitoring of keyboard events

Key Modifiers When listening for keyboard events,...

12 Laws of Web Design for Clean Code [Graphic]

Beautiful code is the foundation of a beautiful we...

How to expand the disk size of a virtual machine

After Vmvare sets the disk size of the virtual ma...

Ubuntu terminal multi-window split screen Terminator

1. Installation The biggest feature of Terminator...

Implementing a simple Christmas game with JavaScript

Table of contents Preface Achieve results Code CS...

Example code for implementing the wavy water ball effect using CSS

Today I learned a new CSS special effect, the wav...

Detailed explanation of views in MySQL

view: Views in MySQL have many similarities with ...

MySQL uses variables to implement various sorting

Core code -- Below I will demonstrate the impleme...

Prototype and prototype chain prototype and proto details

Table of contents 1. Prototype 2. Prototype chain...