Centos8 Nginx 配置開機(jī)自動(dòng)啟動(dòng)

Centos8 Nginx 配置開機(jī)自動(dòng)啟動(dòng)



學(xué)習(xí)下載專區(qū) 【2021-01-16 14:43】


第一步:創(chuàng)建 service文件

vim /lib/systemd/system/nginx.service
  • /lib 與 /usr/lib 我這里配置時(shí)是一樣的,在那個(gè)文件夾配置都可以

第二步:編寫 啟動(dòng)腳本

[Unit]

Description=nginx service

After=network.target

[Service]

Type=forking

PIDFile=/home/app/nginx/log/nginx.pid

ExecStart=/home/app/nginx/sbin/nginx

ExecReload=/home/app/nginx/sbin/nginx -s reload

ExecStop=/home/app/nginx/sbin/nginx -s stop

PrivateTmp=true[Install]

WantedBy=multi-user.target

腳本介紹

Description

服務(wù)描述

After

如果該字段指定的 Unit 也要啟動(dòng),那么必須在當(dāng)前 Unit 之前啟動(dòng)

Type=forking

后臺(tái)運(yùn)行

PIDFile=/home/app/nginx/log/nginx.pid

nginx.pid 文件需要在,nginx配置文件中查找。如果查不到,不配置此屬性也可以

如果type是后臺(tái)運(yùn)行,那么建議將此屬性加上。指定pid。

ExecStart=/home/app/nginx/sbin/nginx

啟動(dòng)腳本

ExecReload=/home/app/nginx/sbin/nginx -s reload

重啟腳本

ExecStop=/home/app/nginx/sbin/nginx -s stop

停止腳本

PrivateTmp=true

是否使用私有tmp目錄

WantedBy=multi-user.target

運(yùn)行級(jí)別下服務(wù)安裝的相關(guān)設(shè)置,可設(shè)置為多用戶,即系統(tǒng)運(yùn)行級(jí)別為3

第三步:保存退出,重新加載systemd

systemctl daemon-reload

重新加載,使 systemd生效

第四步:驗(yàn)證腳本

# 查看服務(wù)狀態(tài)  systemctl status nginx.service
# 停止服務(wù)      systemctl stop nginx.service
# 啟動(dòng)服務(wù)      systemctl start nginx.service
# 重啟服務(wù)      systemctl restart nginx.service

第五步:配置開機(jī)自啟

#開啟開機(jī)自啟
systemctl enable nginx.service
#取消開機(jī)自啟
systemctl disable nginx.service

文件來(lái)源:https://www.cnblogs.com/easonchean/p/14199109.html


友情鏈接:
SQL數(shù)據(jù)庫(kù)修復(fù)專家

——信陽(yáng)市速全網(wǎng)絡(luò)科技有限公司——

版權(quán)所有:信陽(yáng)市速全網(wǎng)絡(luò)科技有限公司

豫ICP備19030104號(hào)-2