Ubuntu

無法重啟 Nginx,“nginx.service 的作業失敗,因為控制程序退出並出現錯誤程式碼。”

  • April 26, 2019

我有一個執行 Ubuntu 16.04 的 digitalocean droplet。我使用 Nginx 提供大部分靜態站點,但它突然停止工作。

(正如你可能從這個介紹中了解到的那樣,我在這一切方面都是初學者。)

我試圖重新啟動nginx:

$ sudo service nginx restart
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.

systemctl 狀態 nginx.service:

$ systemctl status 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 Thu 2019-04-25 12:31:46 UTC; 55s ago
    Docs: man:nginx(8)
 Process: 8232 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
 Process: 8221 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)

journalctl -xe

   $ sudo journalctl -u nginx
   - Logs begin at Thu 2019-03-21 01:07:26 UTC, end at Thu 2019-04-25 12:54:26 UTC. --
Apr 25 10:33:29 ubuntu-s-michaelsimsoe systemd[1]: Stopping A high performance web server and a reverse proxy server...
Apr 25 10:33:29 ubuntu-s-michaelsimsoe systemd[1]: Stopped A high performance web server and a reverse proxy server.
-- Reboot --
Apr 25 10:34:16 ubuntu-s-michaelsimsoe systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 25 10:34:17 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 10:34:17 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 10:34:18 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 10:34:18 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 10:34:18 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 10:34:18 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 10:34:19 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 10:34:19 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 10:34:19 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 10:34:19 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 10:34:20 ubuntu-s-michaelsimsoe nginx[1242]: nginx: [emerg] still could not bind()
Apr 25 10:34:20 ubuntu-s-michaelsimsoe systemd[1]: nginx.service: Control process exited, code=exited status=1
Apr 25 10:34:20 ubuntu-s-michaelsimsoe systemd[1]: nginx.service: Failed with result 'exit-code'.
Apr 25 10:34:20 ubuntu-s-michaelsimsoe systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Apr 25 12:08:48 ubuntu-s-michaelsimsoe systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 25 12:08:48 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:08:48 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:08:49 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:08:49 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:08:49 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:08:49 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:08:50 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:08:50 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:08:50 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:08:50 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:08:51 ubuntu-s-michaelsimsoe nginx[21464]: nginx: [emerg] still could not bind()
Apr 25 12:08:51 ubuntu-s-michaelsimsoe systemd[1]: nginx.service: Control process exited, code=exited status=1
Apr 25 12:08:51 ubuntu-s-michaelsimsoe systemd[1]: nginx.service: Failed with result 'exit-code'.
Apr 25 12:08:51 ubuntu-s-michaelsimsoe systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Apr 25 12:10:24 ubuntu-s-michaelsimsoe systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 25 12:10:25 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:10:25 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:10:25 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:10:25 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:10:26 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:10:26 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:10:26 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:10:26 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:10:27 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:10:27 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:10:27 ubuntu-s-michaelsimsoe nginx[25175]: nginx: [emerg] still could not bind()
Apr 25 12:10:27 ubuntu-s-michaelsimsoe systemd[1]: nginx.service: Control process exited, code=exited status=1
Apr 25 12:10:27 ubuntu-s-michaelsimsoe systemd[1]: nginx.service: Failed with result 'exit-code'.
Apr 25 12:10:27 ubuntu-s-michaelsimsoe systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Apr 25 12:12:59 ubuntu-s-michaelsimsoe systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 25 12:12:59 ubuntu-s-michaelsimsoe nginx[30965]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:12:59 ubuntu-s-michaelsimsoe nginx[30965]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:12:59 ubuntu-s-michaelsimsoe nginx[30965]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 25 12:12:59 ubuntu-s-michaelsimsoe nginx[30965]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 25 12:13:00 ubuntu-s-michaelsimsoe nginx[30965]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

在我注意到錯誤之前,我已經完成了以下操作: * 更改了 root 密碼 * 更改了使用者 michaels 的密碼 * 更改了網站文件夾的所有權(我正在嘗試設置 webhook)

關於它可能是什麼的任何想法?

編輯:一些附加資訊

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

$ ps -A | nginx
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2019/04/25 13:09:32 [warn] 28351#28351: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
2019/04/25 13:09:32 [emerg] 28351#28351: BIO_new_file("/etc/letsencrypt/live/huske.michaelsimsoe.no/fullchain.pem") failed (SSL: error:0200100D:system library:fopen:Permission denied:fopen('/etc/letsencrypt/live/huske.michaelsimsoe.no/fullchain.pem','r') error:2006D002:BIO routines:BIO_new_file:system lib)

在我安裝 nginx 之前,我有一些由 Apache 提供的頁面。我仍然可以達到這些。

其他一些程序已經在執行並綁定到埠 80/443,因此 systemd 無法啟動 nginx。這幾乎總是因為該程序是手動啟動的,而不是通過 systemd 啟動的,或者因為您試圖同時啟動兩個不同的 Web 伺服器。

要解決此問題,請在通過 systemd 重新啟動之前自行終止該程序。

sudo killall apache2

引用自:https://serverfault.com/questions/964568