centos7.x设置nginx开机自启动

分类:CentOS教程 阅读:66116 次

以nginx为例:

假设已经编译安装nginx服务,并将启动脚本存放在/etc/init.d下,以nginx为名,并修改为可执行权限。

[root@yum ~]# cd /lib/systemd/system/

[root@yum system]# vim nginx.service

[Unit]

Description=nginx

After=network.target

[Service]

Type=forking

ExecStart=/etc/init.d/nginx start

ExecReload=/etc/init.d/nginx restart

ExecStop=/etc/init.d/nginx stop

PrivateTmp=true

[Install]

WantedBy=multi-user.target

[root@yumsystem]# systemctl enable nginx.service

[root@yum system]# systemctl start nginx.service

[root@yum system]# netstat -lntp|grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 15136/nginx: master