Ubuntu

Nginx 無法啟動

  • April 8, 2020

我目前正在嘗試設置 nginx 以幫助我在家中執行網站。我已按照以下說明設置 nginx:

sudo apt update
sudo apt install nginx
sudo ufw app list
sudo ufw allow 'Nginx HTTP'
sudo ufw status

一旦我嘗試跑步sudo 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.

執行systemctl status nginx我得到以下資訊:

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 Wed 2020-04-08 16:00:43 BST; 9min ago
    Docs: man:nginx(8)
 Process: 8820 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)

Apr 08 16:00:43 AMCosyClub systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 08 16:00:43 AMCosyClub nginx[8820]: nginx: [emerg] directive "root" is not terminated by ";" in /etc/nginx/conf.d/writefreely.conf:6
Apr 08 16:00:43 AMCosyClub nginx[8820]: nginx: configuration file /etc/nginx/nginx.conf test failed
Apr 08 16:00:43 AMCosyClub systemd[1]: nginx.service: Control process exited, code=exited status=1
Apr 08 16:00:43 AMCosyClub systemd[1]: nginx.service: Failed with result 'exit-code'.
Apr 08 16:00:43 AMCosyClub systemd[1]: Failed to start A high performance web server and a reverse proxy server.

執行journalctl -xe產生

Apr 08 16:00:43 AMCosyClub nginx[8820]: nginx: configuration file /etc/nginx/nginx.conf test failed
Apr 08 16:00:43 AMCosyClub systemd[1]: nginx.service: Control process exited, code=exited status=1
Apr 08 16:00:43 AMCosyClub systemd[1]: nginx.service: Failed with result 'exit-code'.
Apr 08 16:00:43 AMCosyClub systemd[1]: Failed to start A high performance web server and a reverse proxy server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit nginx.service has failed.
-- 
-- The result is RESULT.
Apr 08 16:00:43 AMCosyClub sudo[8817]: pam_unix(sudo:session): session closed for user root
Apr 08 16:00:49 AMCosyClub systemd[1]: Started Run anacron jobs.
-- Subject: Unit anacron.service has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit anacron.service has finished starting up.
-- 
-- The start-up result is RESULT.
Apr 08 16:00:49 AMCosyClub anacron[8821]: Anacron 2.3 started on 2020-04-08
Apr 08 16:00:49 AMCosyClub anacron[8821]: Normal exit (0 jobs run)
Apr 08 16:02:26 AMCosyClub kernel: [UFW BLOCK] IN=wlp8s0 OUT= MAC=redacted SRC=redacted DST=redacted LEN=36 TOS=0x

[1]+  Stopped                 journalctl -xe

我檢查了 nginx 錯誤日誌,它重複以下內容:

[emerg] 8820#8820: directive "root" is not terminated by ";" in /etc/nginx/conf.d/writefreely.conf:6

當涉及到這些東西時,我是一個完全的新手,所以任何幫助將不勝感激。請讓我知道我是否可以提供更多詳細資訊/執行特定命令以幫助進一步澄清正在發生的事情。謝謝!

錯誤消息非常明確:

指令“root”不被“;”終止 在 /etc/nginx/conf.d/writefreely.conf:6

編輯文件:/etc/nginx/conf.d/writefreely.conf

轉到第 6 行

添加 ”;” 在行尾

重啟 nginx

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