nginx开机设置自启动

/etc/systemd/system/ 文件夹下创建一个启动脚本 nginx.service

touch nginx.service
chmod 755 nginx.service
设置文件内容:

[Unit]
 Description=nginx service
 After=network.target

 [Service]
 Type=forking
 ExecStart=/usr/local/nginx/sbin/nginx #nginx安装目录
 ExecReload=/usr/local/nginx/sbin/nginx -s reload
 ExecStop=/usr/local/nginx/sbin/nginx -s quit

 PrivateTmp=true

 [Install]
 WantedBy=multi-user.target

然后执行

systemctl daemon-reload
systemctl enable nginx

nginx启动:systemctl start nginx
nginx停止:systemctl stop nginx
reboot 验证是否开机自启

你可能感兴趣的:(运维,nginx,运维,服务器)