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
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容