CentOS7.4 Nginx添加系統服務及開機自啓動

Nginx安裝好後,每次啓動或者重啓需要進入到/usr/local/nginx下操作,比較麻煩,於是把Nginx添加到系統服務中方便管理:

# 添加nginx.service
# vim /lib/systemd/system/nginx.service

[Unit]
Description=nginx service
After=network.target 

[Service] 
Type=forking
# 路徑對應安裝路徑
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true 

[Install] 
WantedBy=multi-user.target

添加完成後,即可使用systemctl start nginx等進行管理,例如添加開機自啓動:

systemctl enable nginx.service

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章