LoginSignup
31
28

More than 3 years have passed since last update.

【Nginxエラー解決】Job for nginx.service failed because the control process exited with error code.

Last updated at Posted at 2020-09-14

問題

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」を参照してください。

とのこと。

解決法

こちらの記事(Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.などのnginx周りのファイルのエラーを知るコマンド)で教えてもらったのですが、

$ 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はアプリケーション名です

ここが間違ってました↓

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

こちらの記事にそって進めていて、
(デプロイ編②)世界一丁寧なAWS解説。EC2を利用して、RailsアプリをAWSにあげるまで
コピペした時に本来消すべきところが消えずに残ったままになっていたのが原因でした。

(#アプリのElastic 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

今回学んだこと

  • 必ずしもエラーに言われたことをそのままやっただけでは解決できないこともある。やっぱりエラー文でググってみることは大切。
  • 参考記事をコピペする時はコピペしちゃいけないところコピペしたりしてないか、しっかり確認することが必要。
31
28
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
28