更新時(shí)間:2021-07-16 來(lái)源:黑馬程序員 瀏覽量:
把Nginx應(yīng)用服務(wù)設(shè)置成為系統(tǒng)服務(wù),方便對(duì)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)限有問(wèn)題需要進(jìn)行權(quán)限設(shè)置
chmod 755 /usr/lib/systemd/system/nginx.service
(3)使用系統(tǒng)命令來(lái)操作Nginx服務(wù)
啟動(dòng): systemctl start nginx 停止: systemctl stop nginx 重啟: systemctl restart nginx 重新加載配置文件: systemctl reload nginx 查看nginx狀態(tài): systemctl status nginx 開(kāi)機(jī)啟動(dòng): systemctl enable nginx
將本頁(yè)面鏈接http://www.itheima.com/news/20210716/172908.html發(fā)送給QQ:2217622915,免費(fèi)獲取上面課程全套視頻、筆記和源碼。
猜你喜歡: