在CentOS7下将nginx添加到systemctl

来源:互联网 发布:阿里移动推荐算法总结 编辑:程序博客网 时间:2024/05/22 05:22

1、正确安装Nginx
安装Nginx请自行百度

2、将Nginx添加到systemctl
在/usr/lib/systemd/system/下新建文件“nginx.service”
编辑nginx.service,输入如下内容

[Unit]Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/After=network.target remote-fs.target nss-lookup.target[Service]Type=forkingPIDFile=/var/run/nginx.pidExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.confExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.confExecReload=/bin/kill -s HUP $MAINPIDExecStop=/bin/kill -s QUIT $MAINPIDPrivateTmp=true[Install]WantedBy=multi-user.target

编辑保存

3、将Nginx设置为开机启动

[root@localhost init.d]# systemctl enable nginx.service

测试启动Nginx

[root@localhost init.d]# systemctl start nginx.service