首頁技術(shù)文章正文

如何配置Nginx為系統(tǒng)服務(wù)?

更新時(shí)間:2021-07-16 來源:黑馬程序員 瀏覽量:

把Nginx應(yīng)用服務(wù)設(shè)置成為系統(tǒng)服務(wù),方便對Nginx服務(wù)的啟動(dòng)和停止等相關(guān)操作,具體實(shí)現(xiàn)步驟:

(1) 在/usr/lib/systemd/system目錄下添加nginx.service,內(nèi)容如下:

vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx web service
Documentation=http://nginx.org/en/docs/
After=network.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
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=default.target

(2)添加完成后如果權(quán)限有問題需要進(jìn)行權(quán)限設(shè)置

chmod 755 /usr/lib/systemd/system/nginx.service

(3)使用系統(tǒng)命令來操作Nginx服務(wù)

啟動(dòng): systemctl start nginx
停止: systemctl stop nginx
重啟: systemctl restart nginx
重新加載配置文件: systemctl reload nginx
查看nginx狀態(tài): systemctl status nginx
開機(jī)啟動(dòng): systemctl enable nginx

將本頁面鏈接http://www.pantone-color.com.cn/news/20210716/172908.html發(fā)送給QQ:2217622915,免費(fèi)獲取上面課程全套視頻、筆記和源碼。



猜你喜歡:

Nginx使用教程:Nginx從入門到精通

Java中final關(guān)鍵字如何使用?

Java中volatile關(guān)鍵字有什么作用?

JDBC詳細(xì)教程與jdbc連接數(shù)據(jù)庫方法

黑馬程序員java開發(fā)培訓(xùn)課程

分享到:
在線咨詢 我要報(bào)名
和我們在線交談!