前提・実現したいこと
Railsアプリを動かすために、Nginxを起動させたいです。
設定の記述等は完了しています。
発生している問題・エラーメッセージ
sudo systemctl start nginx
で、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のジョブが失敗しました。 詳細については、「systemctlstatusnginx.service」および「journalctl-xe」を参照してください。
試したこと
①systemctlstatusnginx.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-11-11 13:28:43 UTC; 4min 59s ago
Process: 16766 ExecStart=/usr/sbin/nginx (code=exited, status=1/FAILURE)
Process: 16763 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 16762 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
11月 11 13:28:41 ip-10-0-10-10.ap-northeast-1.compute.internal nginx[16766]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
11月 11 13:28:42 ip-10-0-10-10.ap-northeast-1.compute.internal nginx[16766]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
11月 11 13:28:42 ip-10-0-10-10.ap-northeast-1.compute.internal nginx[16766]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
11月 11 13:28:42 ip-10-0-10-10.ap-northeast-1.compute.internal nginx[16766]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
11月 11 13:28:42 ip-10-0-10-10.ap-northeast-1.compute.internal nginx[16766]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
11月 11 13:28:43 ip-10-0-10-10.ap-northeast-1.compute.internal nginx[16766]: nginx: [emerg] still could not bind()
11月 11 13:28:43 ip-10-0-10-10.ap-northeast-1.compute.internal systemd[1]: nginx.service: control process exited, code=exited status=1
11月 11 13:28:43 ip-10-0-10-10.ap-northeast-1.compute.internal systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
11月 11 13:28:43 ip-10-0-10-10.ap-northeast-1.compute.internal systemd[1]: Unit nginx.service entered failed state.
11月 11 13:28:43 ip-10-0-10-10.ap-northeast-1.compute.internal systemd[1]: nginx.service failed.
赤字だった14行目の"Failed to start The nginx HTTP and reverse proxy server."について調べたら、nginx -t
をやってみると良いようだったので、そちらを実行。
②nginx -t
でエラー内容の確認を実施
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2020/11/11 13:35:07 [warn] 16792#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:5
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2020/11/11 13:35:07 [emerg] 16792#0: open() "/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed
**********<翻訳>**********
nginx:[アラート]はエラーログファイルを開くことができませんでした:open() "/var/log/nginx/error.log"が失敗しました(13:アクセスが拒否されました)
2020/11/11 13:35:07 [警告] 16792#0:「user」ディレクティブは、マスタープロセスがスーパーユーザー権限で実行されている場合にのみ意味があり、/etc/nginx/nginx.conf:5では無視されます
nginx:構成ファイル/etc/nginx/nginx.conf構文は問題ありません
2020/11/11 13:35:07 [emerg] 16792#0:open() "/run/nginx.pid"が失敗しました(13:アクセスが拒否されました)
nginx:構成ファイル/etc/nginx/nginx.confテストが失敗しました
③上のエラー内容より、"/var/log/nginx/error.log"と"/run/nginx.pid"はとりあえず権限を"777"へ変更しています。
"/etc/nginx/nginx.conf"は何が問題なのかわかりません。5行目は、"user nginx;"ですが何が問題なのでしょうか?
</etc/nginx/nginx.conf>
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
〜省略〜
よければご回答をよろしくお願いいたします。
こんなことやってみればとか、自分はちょっと違うけどこんなことありました的な内容でも構いませんのでお願いいたします。
-
気になる質問をクリップする
クリップした質問は、後からいつでもマイページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
クリップを取り消します
-
良い質問の評価を上げる
以下のような質問は評価を上げましょう
- 質問内容が明確
- 自分も答えを知りたい
- 質問者以外のユーザにも役立つ
評価が高い質問は、TOPページの「注目」タブのフィードに表示されやすくなります。
質問の評価を上げたことを取り消します
-
評価を下げられる数の上限に達しました
評価を下げることができません
- 1日5回まで評価を下げられます
- 1日に1ユーザに対して2回まで評価を下げられます
質問の評価を下げる
teratailでは下記のような質問を「具体的に困っていることがない質問」、「サイトポリシーに違反する質問」と定義し、推奨していません。
- プログラミングに関係のない質問
- やってほしいことだけを記載した丸投げの質問
- 問題・課題が含まれていない質問
- 意図的に内容が抹消された質問
- 過去に投稿した質問と同じ内容の質問
- 広告と受け取られるような投稿
評価が下がると、TOPページの「アクティブ」「注目」タブのフィードに表示されにくくなります。
質問の評価を下げたことを取り消します
この機能は開放されていません
評価を下げる条件を満たしてません
質問の評価を下げる機能の利用条件
この機能を利用するためには、以下の事項を行う必要があります。
- 質問回答など一定の行動
-
メールアドレスの認証
メールアドレスの認証
-
質問評価に関するヘルプページの閲覧
質問評価に関するヘルプページの閲覧
checkベストアンサー
+1
11月 11 13:28:42 ip-10-0-10-10.ap-northeast-1.compute.internal nginx[16766]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use
エラーログをよく見ると、Address already in use
なので、nginxでない別のプロセスが80番ポートを既に使っているのではないでしょうか?
裏でApacheとかを起動していたりしませんか?
一応、どのプロセスがポートを使っているかはlsof
コマンドで確認できます。
80番ポートを確認するなら下記でできるかと(root権限が必要なのでsudoをつけています)
sudo lsof -i:80
投稿
-
回答の評価を上げる
以下のような回答は評価を上げましょう
- 正しい回答
- わかりやすい回答
- ためになる回答
評価が高い回答ほどページの上位に表示されます。
-
回答の評価を下げる
下記のような回答は推奨されていません。
- 間違っている回答
- 質問の回答になっていない投稿
- スパムや攻撃的な表現を用いた投稿
評価を下げる際はその理由を明確に伝え、適切な回答に修正してもらいましょう。
15分調べてもわからないことは、teratailで質問しよう!
- ただいまの回答率 88.11%
- 質問をまとめることで、思考を整理して素早く解決
- テンプレート機能で、簡単に質問をまとめられる
質問への追記・修正、ベストアンサー選択の依頼
yu_1985
2020/11/12 10:38
sudo nginx -t
を実行して確認してみてください。
nginx -t を実行するユーザに、参照しているファイルを読み込む権限がないせいでconfのテストに失敗しているだけかと。
confのテストに失敗している段階なので、おっしゃる通り現状ではまだ何が原因かはわかりません。
kavvano
2020/11/12 10:51
sudo nginx -t の実行結果はこちらです。
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
内容的に問題ないと思われるのですよね。
他に確認すべきことなどありましたら、教えていただけますと幸いです。