zoukankan      html  css  js  c++  java
  • Centos7 解压版Nginx如何设置开机自启动

    Centos7 解压版Nginx如何设置开机自启动

    第一步:创建nginx.service 文件

    vim /lib/systemd/system/nginx.service
    

    第二步:添加以下内容,我的目录在/usr/local/nginx/下

    [Unit]
    Description=nginx service
    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
    

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

    第三步:开机自启动

    systemctl enable nginx
    

    其他常用命令

    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         停止开机自启动
    

    常见的错误

    Warning: nginx.service changed on disk. Run 'systemctl daemon-reload' to reload units.
     直接按照提示执行命令systemctl daemon-reload 即可。
    
  • 相关阅读:
    Bzoj 1537: [POI2005]Aut- The Bus 题解 [由暴力到正解]
    Bzoj 3126[Usaco2013 Open]Photo 题解
    Bzoj 3165 [Heoi2013]Segment题解
    Bzoj 2733: [HNOI2012]永无乡 数组Splay+启发式合并
    赛前集训前的总结(警醒)
    bzoj3316 JC loves Mkk题解
    9.22考试 crf的军训 题解
    Luogu3521 [POI2011]ROT-Tree Rotations
    CTSC2012 熟悉的文章
    UVA11468 Substring
  • 原文地址:https://www.cnblogs.com/cnsyear/p/12730914.html
Copyright © 2011-2022 走看看