【Nginx错误解决】由于控制进程退出并返回错误代码,导致nginx.service作业失败

請問有什麼問題嗎?

当您输入以下命令启动Nginx时,

$ sudo service nginx start

出现了以下错误。

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 作业失败。有关详细信息,请参阅 “systemctl status nginx.service” 和 “journalctl -xe”。

这是怎么回事。 (Zhè shì .)

答案将取决于上下文,以下提供两种可能的中文翻译选项:

选项1: 解决方案 (jiě jué àn)

选项2: 解决办法 (jiě jué fǎ)

我从这篇文章中得到了有关nginx文件错误的命令(Job for nginx.service failed because the control process exited with error code. See “systemctl status nginx.service” and “journalctl -xe” for details.)

$ sudo nginx -t

显示出了这是什么问题。

nginx: [emerg] unknown directive "(#アプリのElastic" in /etc/nginx/conf.d/pfc-master.conf:14
nginx: configuration file /etc/nginx/nginx.conf test failed

似乎在 /etc/nginx/conf.d/pfc-master.conf 文件中有错误。

我现在知道了,错误的修正内容可能不同,但是通过修改/etc/nginx/conf.d/pfc-master.conf文件来修正应该是正确的,这得益于这篇文章。
当在nginx连接中出现”nginx: [emerg] unknown directive “ ””的错误时的解决方法。

用 Vim 打开 /etc/nginx/conf.d/pfc-master.conf 文件。

$ sudo vim /etc/nginx/conf.d/pfc-master.conf
※pfc-masterはアプリケーション名です

这里是错误的地方↓ (Zhè lǐ shì cuò wù de dì ↓)

server {
  server_name 11.111.11.11;(#アプリのElastic IPに変更してください)
}

按照这篇文章的指示进行操作,(部署篇②)详细解说AWS。利用EC2将Rails应用程序上传到AWS。
导致问题的原因是在复制粘贴时,本来应该删除的部分没有被删除。
请删除”#应用的弹性IP更改”这一部分。

server_name 11.111.11.11;

我进行了修正后问题解决了。

顺便提一下

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.service”和”journalctl -xe”。),问题并未解决。

实际上就像错误所说的那样

$ systemctl status nginx.service

我使用”叩击systemctl status nginx.service”进行了参考。

● 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 月 2020-09-14 10:34:31 UTC; 11min ago
  Process: 15185 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE)
  Process: 15184 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

只是显示出这些内容,并没有得到应该解决的修改点。

nginx: [emerg] unknown directive "(#アプリのElastic" in /etc/nginx/conf.d/pfc-master.conf:14
nginx: configuration file /etc/nginx/nginx.conf test failed

我在这次学习中所获得的教训

    • 必ずしもエラーに言われたことをそのままやっただけでは解決できないこともある。やっぱりエラー文でググってみることは大切。

 

    参考記事をコピペする時はコピペしちゃいけないところコピペしたりしてないか、しっかり確認することが必要。
bannerAds