故障 -> nginx啟動失敗


描述:在用saltstack給 minion 安裝 nginx 服務 時 提示 nginx 服務下載成功,但是啟動失敗。

----------
          ID: nginx-systemctl
    Function: service.running
        Name: nginx
      Result: False
     Comment: Service nginx failed to start
     Started: 09:32:48.221250
    Duration: 3317.741 ms
     Changes:   
              ----------
              nginx:
                  False

然后就去minion 端查看了一下 端口是否開啟  netstat -lntup  發現沒有nginx  進程也沒有

然后手動起了一下 提示 如下報錯:

[root@salt1-minion ~]# systemctl start nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

意思就是Nginx服務起不來了,然后查看一下狀態吧, systemctl status nginx

[root@salt1-minion ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2018-11-21 09:33:38 CST; 15s ago
  Process: 1475 ExecStart=/usr/sbin/nginx (code=exited, status=1/FAILURE)
  Process: 1472 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 1471 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

Nov 21 09:33:37 salt1-minion nginx[1475]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) Nov 21 09:33:37 salt1-minion nginx[1475]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Nov 21 09:33:37 salt1-minion nginx[1475]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Nov 21 09:33:38 salt1-minion nginx[1475]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Nov 21 09:33:38 salt1-minion nginx[1475]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Nov 21 09:33:38 salt1-minion systemd[1]: nginx.service: control process exited, code=exited status=1
Nov 21 09:33:38 salt1-minion nginx[1475]: nginx: [emerg] still could not bind()
Nov 21 09:33:38 salt1-minion systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Nov 21 09:33:38 salt1-minion systemd[1]: Unit nginx.service entered failed state.
Nov 21 09:33:38 salt1-minion systemd[1]: nginx.service failed.

從報錯信息中會看到,Address already in use意思就是地址已經被使用了。當時發現了自己的失誤,原來是之前下載過httpd ,也是80端口。

那就去修改一下nginx 的配置文件吧 ,修改端口,去到 /etc/nginx/nginx.conf文件里,把端口修改為443

 server {
        listen       443 default_server;
        listen       [::]:443 default_server;

然后重新啟動服務

[root@salt1-minion nginx]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      914/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1001/master         
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      1507/nginx: master  
tcp6       0      0 :::80                   :::*                    LISTEN      919/httpd           
tcp6       0      0 :::22                   :::*                    LISTEN      914/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1001/master         
tcp6       0      0 :::443                  :::*                    LISTEN      1507/nginx: master  
[root@salt1-minion nginx]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2018-11-21 09:35:20 CST; 9s ago
  Process: 1505 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)

最后網頁訪問 主機加端口測試,沒有問題。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM