环境
centos6
描述
设置Nginx开机启动,当服务器重启后,可自行启动nginx
1.创建nginx.service文件
vim /usr/lib/systemd/system/nginx.service
2.写入内容
[Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s stop PrivateTmp=true [Install] WantedBy=multi-user.target
其中【/usr/local/nginx/sbin/nginx】为nginx安装目录下的启动路径
3.设置开启启动
cd /usr/lib/systemd/system
systemctl enable nginx.service