質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

解決済

1回答

5186閲覧

Nginxが起動しないエラーを解決したいです。

kavvano

総合スコア47

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

1クリップ

投稿2020/11/11 13:59

編集2020/11/11 14:17

前提・実現したいこと

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; 〜省略〜

よければご回答をよろしくお願いいたします。
こんなことやってみればとか、自分はちょっと違うけどこんなことありました的な内容でも構いませんのでお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yu_1985

2020/11/12 01:38

sudo nginx -t を実行して確認してみてください。 nginx -t を実行するユーザに、参照しているファイルを読み込む権限がないせいでconfのテストに失敗しているだけかと。 confのテストに失敗している段階なので、おっしゃる通り現状ではまだ何が原因かはわかりません。
kavvano

2020/11/12 01: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 内容的に問題ないと思われるのですよね。 他に確認すべきことなどありましたら、教えていただけますと幸いです。
guest

回答1

0

ベストアンサー

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をつけています)

bash

1sudo lsof -i:80

参考
このポートで実行中のプロセスはどれ? lsofコマンドの使い方

投稿2020/11/12 02:02

yu_1985

総合スコア7447

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kavvano

2020/11/12 02:48 編集

Apacheを起動させていました。お手数をおかけし申し訳ありません。 対処した際のコマンドを一応記載しておきます。 % sudo lsof -i:80 # 起動プロセスの確認(今回はアパッチが起動していた) % sudo systemctl stop httpd.service # アパッチ停止 % sudo systemctl status httpd.service # アパッチのステータスを確認(Active: inactiveであることを確認) % sudo systemctl start nginx # エンジンエックス起動 % sudo systemctl status nginx # エンジンエックスのステータス(Active: active)を確認 本当にありがとうございました。 エラーをしっかり読み解くようにしたいと思います。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問