RHEL/CentOS 7中Nginx的systemd service
源码安装的nginx ,没有systemd service 管理 nginx
下面教程,告诉你如何设置nginx 的systemd service
nginx systemd的服务文件是/usr/lib/systemd/system/nginx.service
[Unit] Description=The NGINX HTTP and reverse proxy server After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
为了启动Nginx的systemd服务,步骤如下:
1. 设置nginx.service文件的权限
chmod 664 /usr/lib/systemd/system/nginx.service
2.开启服务启动时执行
systemctl enable nginx.service
3.启动服务
systemctl start nginx.service
4.查看服务状态
systemctl status nginx.service
5.停止服务
systemctl stop nginx.service
6.重载服务
systemctl reload nginx.service