CentOS 7 將 nginx 配置成系統服務

在CentOS 7中對用戶安裝的應用服務設置爲系統服務,比CentOS 6方便不少,下面以配置nginx爲系統服務爲例子進行說明。nginx

本例中的nginx採用源碼編譯方式進行安裝,安裝位置在/usr/local/nginx。要配置nginx爲系統服務,須要有nginx.service文件,執行以下操做,編寫service腳本。web

vi /usr/lib/systemd/system/nginx.service #nginx.service內容bash

[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=/your nginx pid file path/nginx.pid
ExecStartPre=/your nginx path/sbin/nginx -t -c /your nginx path/conf/nginx.conf
ExecStart=/your nginx path/sbin/nginx -c /your nginx path/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

 

添加完以後,開啓服務code

systemctl enable nginx.serviceorm

systemctl daemon-reload
相關文章
相關標籤/搜索