微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

[转]centos7.2 下 nginx 开机启动

1.在系统服务目录里创建Nginx.service文件

vi /lib/systemd/system/Nginx.service

内容如下

[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 quit
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target

[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3

:wq   保存退出

 

2.设置开机启动

    
systemctl enable Nginx.service

 

3.其他命令

启动Nginx服务

systemctl start Nginx.service

设置开机自启动

systemctl enable Nginx.service

停止开机自启动

systemctl disable Nginx.service

查看服务当前状态

systemctl status Nginx.service

重新启动服务

systemctl restart Nginx.service 

查看所有已启动的服务

systemctl list-units --type=service

 

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

相关推荐