zoukankan      html  css  js  c++  java
  • Centos8配置Nginx开机自启动

    第一步:创建service文件,并编辑(可理解为开机时自动启动Nginx的脚本服务文件)

    vim /lib/systemd/system/nginx.service
    • /lib 与 /usr/lib 里的配置是一样的,在哪个文件下配置都可以

    第二步:编写 启动脚本

    [Unit]
    
    Description=nginx service
    
    After=network.target
    
    [Service]
    
    Type=forking
    
    ExecStart=/usr/local/nginx/sbin/nginx         //nginx的可执行路径
    
    ExecReload=/opt/nginx/sbin/nginx -s reload 
    ExecStop=/opt/nginx/sbin/nginx -s stop
    
    PrivateTmp=true
    
    [Install]
    
    WantedBy=multi-user.target    

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

    第三步:加入开机自启动

    # systemctl enable nginx.service

    第四步:服务的启动/停止/查看状态

    # systemctl start nginx.service  启动nginx服务
    
    # systemctl stop nginx.service           停止服务
    
    # systemctl restart nginx.service       重新启动服务
    
    # systemctl list-units --type=service    查看所有已启动的服务
    
    # systemctl status nginx.service          查看服务当前状态
    
    # systemctl enable nginx.service          设置开机自启动
    
    # systemctl disable nginx.service        停止开机自启动

    至此结束!

  • 相关阅读:
    document.getElementById(), getElementsByname(),getElementsByClassName(),getElementsByTagName()方法表示什么以及其意义
    Go -10 Go Web 简单实现
    Go -09 Go 函数和方法区别
    Go -08 Go win 环境搭建
    Go-07 Go 规范代码风格
    Go-06 Go 语言注释(comment)
    Go-05 Go 转义字符
    Go-04 Go 语法要求和注意事项
    Go-03 Go 快速入门
    Go-02 搭建 Go 开发环境(mac系统)
  • 原文地址:https://www.cnblogs.com/Jack-Cheng008/p/14863063.html
Copyright © 2011-2022 走看看