欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 产业 > Linux设置Nginx开机启动

Linux设置Nginx开机启动

2025/5/5 13:00:27 来源:https://blog.csdn.net/BillKu/article/details/143746264  浏览:    关键词:Linux设置Nginx开机启动

操作系统环境:CentOS 7

【需要 root 权限,使用 root 用户进行操作】

原理:利用 systemctl 管理服务

设置 Nginx 开机启动

需要 root 权限,普通用户使用 sudo 进行命令操作

原理:利用 systemctl 管理服务

1、新建服务

在 /usr/lib/systemd/system 目录下,新建 nginx.service 文件,配置内容

sudo vim /usr/lib/systemd/system/nginx.service

配置内容如下: 

[Unit]
Description=Nginx Server
After=nginx.service[Service]
User=root
Group=root
Type=forking
ExecStart=/export/server/nginx/sbin/nginx -c /export/server/nginx/conf/nginx.conf
ExecStop=/export/server/nginx/sbin/nginx -s quit
ExecReload=/export/server/nginx/sbin/nginx -s reload
Restart=on-failure
PrivateTmp=true[Install]
WantedBy=multi-user.target

2、重新加载 systemctl

sudo systemctl daemon-reload

3、启动 Nginx

sudo systemctl start nginx.service;ps -ef | grep nginx

4、设置 Nginx 开机启动

设置开机启动

sudo systemctl enable nginx.service

查看设置情况

sudo systemctl is-enabled nginx

5、重启计算机

sudo reboot

6、验证 Nginx 开机启动

sudo systemctl status nginx.service;ps -ef | grep nginx

附+:Nginx 的其他命令

1、取消 Nginx 开机启动

sudo systemctl disable nginx.service

2、重启 Nginx

当前 Nginx 运行或停止状态都可以 restart

sudo systemctl restart nginx.service

 只能在当前 Nginx 运行状态 reload

sudo systemctl reload nginx.service

3、停止 Nginx

sudo systemctl stop nginx.service

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词