• centos7 ngxin启动失败:Job for nginx.service failed(80端口被占用的解决办法)


    问题描述:
    (flaskApi) [root@67 flaskDemo]# service nginx start Redirecting to /bin/systemctl start nginx.service Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

      确认问题:

      当不能使用service nginx start 开启或者使用service nginx stop 关闭时,查看systemctl status nginx 会有一定的错误提示

    systemctl status nginx -l

      -l表示:可以展示全部错误信息,否则可能错误信息会被折叠

      Hint: Some lines were ellipsized, use -l to show in full.  

      返回的错误提示:

      从这里我们可以看出,是80端口被占用了

    9月 17 14:54:21 67.59.247.60.static.bjtelecom.net nginx[25531]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) 

       通过命令查看80端口被哪个进程占用了

    netstat -tpnul 

      可以看到是httpd,这个进程需要是24小时启动了,不能关掉

       所以接下来的解决办法有2种

      • 修改nginx的配置文件nginx.conf指定nginx启动时使用别的端口号,例如81
      • 或者杀掉占用80端口的进程,参照:centOS7杀死进程命令

      查看nginx的安装目录,并找到nginx.conf的目录:

    rpm -ql grep nginx

     

      或者直接使用find命令查找 nginx.conf

    (flaskApi) [root@67 flaskDemo]# find / -name nginx.conf
    /etc/nginx/nginx.conf

      使用nano命令编辑nginx.conf配置文件,图示中2处默认为80的端口号改为81

    nano /etc/nginx/nginx.conf

     

    另外应当注意:

    service nginx start 是centos6.x的命令 , centos7.x使用 systemctl start nginx

    再次启动nginx,没看到启动成功的提示信息

    (flaskApi) [root@67 flaskDemo]# /bin/systemctl start nginx.service

    打印一下当前的进程,可以看到nginx已经启动了,并且使用的是81端口

    参照文档:

    Nginx修改默认端口80

    nginx 在Centos 7 版本的yum安装 和目录解释

     

    nginx启动报错的处理办法,参照:

    https://blog.csdn.net/qq_40907977/article/details/91989353

  • 相关阅读:
    SVN使用方法
    NHiberante3.2 调用存储过程之Errors in named queries:
    AjaxFileUpload + *.ashx 文件上传在IE8.0(XP,VS2010,Development Server)下的注意
    PB中设置SQLCA.AutoCommit = False的说明
    UrlRoutingModel摘要
    PB中的大数据量插入操作测试
    PB TreeView控件
    关于端口共用
    关于RealProxy
    EF无法更新错误
  • 原文地址:https://www.cnblogs.com/kaerxifa/p/11534097.html
Copyright © 2020-2023  润新知