LoginSignup
16
8

More than 5 years have passed since last update.

EC2でRailsアプリを起動したけどブラウザからアクセスできないとき

Last updated at Posted at 2018-05-17

環境

OSは AmazonLinux

$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
$ rails -v
Rails 5.2.2

困ったこと

EC2インスタンスの中に、Railsアプリを作りました。

$ bundle exec rails server -p 3000
=> Booting Puma
=> Rails 5.2.0 application starting in development 
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.4 (ruby 2.5.1-p57), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop

とやって、サーバーは起動しました。

ブラウザから

http://(インスタンスのパブリックIP address):3000

にアクセスすると

ng.png

になってしまいました。こまった。

解決策

-b 0.0.0.0 をつけるといい。

$ bundle exec rails server -p 3000 -b 0.0.0.0
=> Booting Puma
=> Rails 5.2.0 application starting in development 
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.4 (ruby 2.5.1-p57), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop

ってやって http://(インスタンスのパブリックIP address):3000 にアクセスするとYay!

ok.png

こちらの情報をいただきました。ありがとうございます。

16
8
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
16
8