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

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

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

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

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

AWS(Amazon Web Services)

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

Q&A

解決済

1回答

3507閲覧

AWS EC2でnginxが起動できない

退会済みユーザー

退会済みユーザー

総合スコア0

nginx

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

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

AWS(Amazon Web Services)

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

0グッド

0クリップ

投稿2020/01/09 12:57

編集2020/01/09 22:34

AWS EC2でnginxの起動をを試みていますがエラーが出て起動ができません。
背景と経緯を記載します。
Nginx起動への解決策を教えていただけると助かります。

背景:AWS(EC2)にRailsのWebアプリをデプロイ
参考:https://qiita.com/iwaseasahi/items/b28f8b91c4638e2c57fd

Nginxをインストール:
コマンド:$ sudo yum install -y nginx
でインストールできなかったので代わりに以下でインストール
コマンド:$ sudo amazon-linux-extras install nginx1
結果:Installed: nginx.x86_64 1:1.16.1-1.amzn2.0.1
確認:$ nginx -v => nginx version: nginx/1.16.1

Nginxを起動:
コマンド1:$ sudo /etc/init.d/nginx start
結果:command not found

コマンド2:$ sudo service nginx start
結果:Redirecting to /bin/systemctl start nginx.service
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

コマンド3:$ sudo /bin/systemctl start nginx.service
結果:The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.

追記:参考のためステータスを出力しました
コマンド:$ sudo 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 Thu 2020-01-09 13:04:39 UTC; 21s ago
Process: 31933 ExecStart=/usr/sbin/nginx (code=exited, status=1/FAILURE)
Process: 31929 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 31928 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

Jan 09 13:04:37 ip-10-0-10-10.ec2.internal nginx[31933]: nginx: [emerg] bind() to [::]...)
Jan 09 13:04:38 ip-10-0-10-10.ec2.internal nginx[31933]: nginx: [emerg] bind() to 0.0....)
Jan 09 13:04:38 ip-10-0-10-10.ec2.internal nginx[31933]: nginx: [emerg] bind() to [::]...)
Jan 09 13:04:38 ip-10-0-10-10.ec2.internal nginx[31933]: nginx: [emerg] bind() to 0.0....)
Jan 09 13:04:38 ip-10-0-10-10.ec2.internal nginx[31933]: nginx: [emerg] bind() to [::]...)
Jan 09 13:04:39 ip-10-0-10-10.ec2.internal nginx[31933]: nginx: [emerg] still could no...)
Jan 09 13:04:39 ip-10-0-10-10.ec2.internal systemd[1]: nginx.service: control process ...1
Jan 09 13:04:39 ip-10-0-10-10.ec2.internal systemd[1]: Failed to start The nginx HTTP ....
Jan 09 13:04:39 ip-10-0-10-10.ec2.internal systemd[1]: Unit nginx.service entered fail....
Jan 09 13:04:39 ip-10-0-10-10.ec2.internal systemd[1]: nginx.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

追記2:コマンドの結果を記載しました。
コマンド1: $ sudo systemctl -l 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 Thu 2020-01-09 22:30:15 UTC; 19s ago
Process: 1077 ExecStart=/usr/sbin/nginx (code=exited, status=1/FAILURE)
Process: 1074 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 1073 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

Jan 09 22:30:14 ip-10-0-10-10.ec2.internal nginx[1077]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jan 09 22:30:14 ip-10-0-10-10.ec2.internal nginx[1077]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 09 22:30:14 ip-10-0-10-10.ec2.internal nginx[1077]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jan 09 22:30:15 ip-10-0-10-10.ec2.internal nginx[1077]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 09 22:30:15 ip-10-0-10-10.ec2.internal nginx[1077]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Jan 09 22:30:15 ip-10-0-10-10.ec2.internal nginx[1077]: nginx: [emerg] still could not bind()
Jan 09 22:30:15 ip-10-0-10-10.ec2.internal systemd[1]: nginx.service: control process exited, code=exited status=1
Jan 09 22:30:15 ip-10-0-10-10.ec2.internal systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Jan 09 22:30:15 ip-10-0-10-10.ec2.internal systemd[1]: Unit nginx.service entered failed state.
Jan 09 22:30:15 ip-10-0-10-10.ec2.internal systemd[1]: nginx.service failed.

コマンド2: $ sudo nginx -t
結果: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

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

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

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

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

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

scsi

2020/01/09 13:22

sudo yum install -y nginx でなぜインストールできなかったのですか?
yu_1985

2020/01/09 18:21

横からですが、Amazon Linux2では正しい挙動です
yu_1985

2020/01/09 18:31

sudo systemctl -l status nginx.service sudo nginx -t あたりの結果を貼ってください
退会済みユーザー

退会済みユーザー

2020/01/09 22:34

scsi様、yu_1985様、コメントありがとうございます。 コマンドの結果を追記しました。 ご確認よろしくお願いします。
guest

回答1

0

ベストアンサー

何かが邪魔してるのかと思い、調べてみたら前に自動起動設定したApacheがあるのを思い出しました。
削除して以下でインストールしてステータス出力したらactiveになってたので、多分大丈夫だと思います。(1インスタンスでApacheとNginxの両方がなぜ使えないのかはまだ分かりませんが)
ご協力ありがとうございました!

$ sudo /bin/systemctl start nginx.service
$ sudo 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: active (running) since Thu 2020-01-09 22:54:36 UTC; 20s ago
Process: 1498 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 1495 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 1494 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 1501 (nginx)
CGroup: /system.slice/nginx.service
├─1501 nginx: master process /usr/sbin/nginx
└─1502 nginx: worker process

Jan 09 22:54:36 ip-10-0-10-10.ec2.internal systemd[1]: Starting The nginx HTTP and rev....
Jan 09 22:54:36 ip-10-0-10-10.ec2.internal nginx[1495]: nginx: the configuration file ...k
Jan 09 22:54:36 ip-10-0-10-10.ec2.internal nginx[1495]: nginx: configuration file /etc...l
Jan 09 22:54:36 ip-10-0-10-10.ec2.internal systemd[1]: Failed to read PID from file /r...t
Jan 09 22:54:36 ip-10-0-10-10.ec2.internal systemd[1]: Started The nginx HTTP and reve....
Hint: Some lines were ellipsized, use -l to show in full.

投稿2020/01/09 23:07

退会済みユーザー

退会済みユーザー

総合スコア0

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

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

yu_1985

2020/01/10 02:13

エラーになってしまったのは Jan 09 22:30:14 ip-10-0-10-10.ec2.internal nginx[1077]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) というメッセージを見ても分かる通り、nginxが使おうとしているポートが既に使われているからでしょうね。 両方を起動する理由も特にないでしょうけど…。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問