閱讀660 返回首頁    go 支付寶


CentOS 7 配置nginx的service 腳本例子

在CentOS 7中對用戶安裝的應用服務設置為係統服務,比CentOS 6方便很多,下麵以配置nginx為係統服務為例子進行說明。

本例中的nginx采用源碼編譯方式進行安裝,安裝位置在/usr/local/nginx。要配置nginx為係統服務,需要有nginx.service文件,執行如下操作,編寫service腳本。


vim /usr/lib/systemd/system/nginx.service
#nginx.service內容

[Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
#賦予腳本執行權限
chmod +x /usr/lib/systemd/system/nginx.service
#設置nginx.service為係統服務
systemctl enable nginx.service

##通過係統服務操作nginx
systemctl start nginx.service
systemctl reload nginx.service
systemctl restart nginx.service
systemctl stop nginx.service



最後更新:2017-07-09 22:02:22

  上一篇:go  HI 阿裏雲
  下一篇:go  Swift a tour