使用systemctl方式管理nginx方式
更新时间:2025年06月05日 09:40:16 作者:肥美怪叫兔
这篇文章主要介绍了使用systemctl方式管理nginx方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
1.源码安装的nginx
不能使用systemctl方式进行管理,所以需要创建配置文件
vim /usr/lib/systemd/system/nginx.service
2.写入以下内容
[Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID [Install] WantedBy=multi-user.target
3.重载配置文件
systemctl daemon-reload
然后就可以使用systemctl方式管理nginx啦
- 启动nginx服务
systemctl start nginx
- 查看nginx服务运行状态
systemctl status nginx
- 关闭nginx服务
systemctl stop nginx
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
Nginx性能优化之Gzip压缩设置详解(最大程度提高页面打开速度)
这篇文章主要介绍了Nginx性能优化之Gzip压缩设置详解(最大程度提高页面打开速度),需要的朋友可以参考下2022-01-01
服务器报错nginx 502 Bad Gateway的原因及如何解决详解
项目启动时莫名其妙网站访问不了,502 Bad Gateway,下面这篇文章主要给大家介绍了关于服务器报错nginx 502 Bad Gateway的原因及如何解决的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下2023-06-06


最新评论