当前位置: 代码网 > 服务器>服务器>Linux > 使用systemctl方式管理nginx方式

使用systemctl方式管理nginx方式

2025年06月05日 Linux 我要评论
1.源码安装的nginx不能使用systemctl方式进行管理,所以需要创建配置文件vim /usr/lib/systemd/system/nginx.service2.写入以下内容[unit]des

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

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com