centos7使用systemctl控制nginx

1.创建nginx.service

vim /usr/lib/systemd/system/nginx.service

2.编辑如下内容

[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
WorkingDirectory=/usr/local/nginx
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true


[Install]
WantedBy=multi-user.target

3.使文件生效

systemctl daemon-reload

4.启动nginx

systemctl start nginx

关闭nginx

systemctl stop nginx

重启nginx

systemctl restart nginx

5.开机启动

systemctl enable nginx

你可能感兴趣的:(centos7使用systemctl控制nginx)