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
相关文章
相关标签/搜索