CentOS 7下使用systemctl为Nginx启用进程守护实现开机自启

1、cd到指定目录

cd /usr/lib/systemd/system

2、创建nginx.service

vi nginx.service

3.输入以下内容,路径为nginx安装路径

[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=/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 -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

设置开机启动

systemctl enable nginx

其它命令

#重启应用
systemctl restart nginx

#停止应用
systemctl stop nginx

#查看应用的日志
systemctl status nginx
posted @ 2019-12-27 15:21  一事冇诚  阅读(524)  评论(0编辑  收藏  举报