Unable to connect to Rails server running on EC2 from the public IP address

I recently had a problem with AWS EC2 instances. The problem is that I cannot hit the Rails servers through the public IP address, but I can hit the localhost and the server will respond.

That's what I'm doing:

  • Create a new instance of EC2 (t2.micro, ubuntu free tier)
  • The security group has a port 22, 80, 3000, open to all (0.0.0.0)
  • SSH for EC2 instance, install rails (I used this for installation)
  • Run the rails server after installation, it runs on the 3000 server
  • run "wget ​​localhost: 3000" and it returns index.html, yay!
  • go to my web browser, enter the public IP address of the EC2 instance and port 3000 (IP: 3000), says that it cannot connect: (
  • kill the rails server, restart it on port 80, wget works, but cannot connect via public IP
  • as a health check, I install nginx and run it, and also see the nginx start page on port 80 through the public IP ... so confused ...

So, I think this is due to the way I install Rails, but I tried other methods besides using this setup script, but I am facing the same problem ... I even tried to create a completely new AWS account in case if I messed up the settings in my original account but no luck. I was previously able to get rails running on EC2 instances just fine (actually I have EC2 instances that use the same security group as now on my AWS account and can just hit these public IP addresses ), but now I'm just banging my head against the wall ... any help would be greatly appreciated!

EDIT: At the moment, I have configured nginx on my rails server ... at least it works at the moment ... although I am still wondering why I cannot directly hit my rails server ...

+6
source share
3 answers

Check if the rails are listening on 0.0.0.0 or 127.0.0.1, by default this is listening only on localhost.

-b, --binding=IP Binds Rails to the specified IP. Default: localhost 

From the Ruby on Rails 4.2 Release Notes :

Due to a change in Rack, the rails server now listens on localhost instead of the default 0.0.0.0. This should have a minimal impact on the standard development workflow like http: //127.0.0.1haps000 and http: // localhost: 3000 will continue to work as before on your own machine.

+11
source

If you use a "rails server" and want to use port 3000 by default, use below:

 sudo rails server -b 0.0.0.0 

it can be accessed as http://[public_ip]:3000 .

If you want to use it as a URL without a port, use below to start the server:

 sudo rails server -p 80 -b 0.0.0.0 

You simply access it as http://[public_ip] .

+1
source

I started the default rails server by default of 3000 on my AWS Ubuntu instance and allowed this port in the security group, the inbound section, but still I was not able to access my application using this.
http: // public_ip: 3000

I searched a lot and the answer helped me. An explanation of the answer. We need to make the firewall flexible so that our firewall allows port 3000.

You can use this command to check if this port is allowed in the firewall or not.

 $ sudo iptables -L | grep :3000 

If you do not see anything, this means that we must resolve this with this command.

 $ sudo iptables -A INPUT -p tcp --dport 3000 -j ACCEPT 

This helped me access my rails on port 3000.

0
source

Source: https://habr.com/ru/post/983004/


All Articles