CentOS 7 nginx启动脚本

starlin 710 2018-04-28

Centos7使用systemd代替之前的systemv的启动脚本,可以说更简单。不再需要编写一长段脚本
复制以下内容到/usr/lib/systemd/system/nginx.service

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

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

然后就可使用systemctl start|stop|reload|restart nginx 进行启动重启等操作。

systemctl enable nginx即可实现开机启动。

systemctl disable nginx取消开机启动。


# Nginx