2017-01-02 175 views
1

我在Ubuntu 16.04上安裝了NGINX並編輯了我的配置。 當我想用sudo service nginx restart重新啓動我的錯誤:重新啓動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.service狀態的內容:

nginx.service - A high performance web server and a reverse proxy server 
    Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) 
    Active: failed (Result: exit-code) since Mon 2017-01-02 16:07:54 UTC; 15s ago 
    Process: 26515 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE) 
    Process: 26510 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) 
Main PID: 3464 (code=exited, status=0/SUCCESS) 

Jan 02 16:07:53 IF-STG-001 nginx[26515]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) 
Jan 02 16:07:53 IF-STG-001 nginx[26515]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 
Jan 02 16:07:53 IF-STG-001 nginx[26515]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) 
Jan 02 16:07:54 IF-STG-001 nginx[26515]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 
Jan 02 16:07:54 IF-STG-001 nginx[26515]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) 
Jan 02 16:07:54 IF-STG-001 nginx[26515]: nginx: [emerg] still could not bind() 
Jan 02 16:07:54 IF-STG-001 systemd[1]: nginx.service: Control process exited, code=exited status=1 
Jan 02 16:07:54 IF-STG-001 systemd[1]: Failed to start A high performance web server and a reverse proxy server. 
Jan 02 16:07:54 IF-STG-001 systemd[1]: nginx.service: Unit entered failed state. 
Jan 02 16:07:54 IF-STG-001 systemd[1]: nginx.service: Failed with result 'exit-code'. 

爲什麼我不能重新啓動我的nginx的實例?我不明白爲什麼它是阻斷重啓

回答

2

錯誤信息的重要組成部分,是

bind() to 0.0.0.0:80 failed (98: Address already in use)

因此,在啓動時,nginx的無法綁定到端口80,因爲其他一些程序已經綁定到這個端口。當其他程序退出或取消綁定此套接字時,您將只能啓動nginx。

要找到哪個程序當前綁定這個端口,可以爲根的(sudo如)運行此命令:

ss -ntlp "sport = :80" 
+0

當我執行,我得到:'國家的Recv-Q發送-Q本地地址:端口對端地址:端口 LISTEN 0 128 *:80 *:* LISTEN 0 128 ::: 80 ::: *' – sesc360

+0

請務必以root身份運行程序。普通用戶沒有權限檢查哪個程序綁定到某個端口。 –

+0

好的,所以現在的輸出是 'State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:80 *:* users:((「nginx」,pid = 26359,fd = (「nginx」,pid = 26359,fd = 7),(「nginx」,pid = 26358,fd = 6)) LISTEN 0 128 ::: 80 ::: * users: ,pid = 26358,fd = 7))' – sesc360