Puma is not working on server - ruby-on-rails

I have rails 5 app running on my ubuntu 14.04 server on top of nginx. But when I am trying to start the rails app its throwing error
/usr/local/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/binder.rb:266:in initialize': Cannot assign requested address - bind(2) for "example.com" port 3000 (Errno::EADDRNOTAVAIL)

While RAILS is not my area, this sounds like either port 3000 is already in use, or DNS is failing to resolve the hostname example.com (which I'm aware is not the actual hostname)
Check that this same system can ping the hostname, which is a quick way to tell if DNS is resolving it. If not, you can make an entry for it in the systems /etc/hosts file

Related

Rails: Permission denied - bind(2) for “127.0.0.1” port 3000 (Errno::EACCES)

When I try to run my rails server in port 3000 I get this error. I can run the server in a different port and it works but I want that to run in port 3000.
I have tried to check if this port is busy and to kill the process but every time I do that I find the port is free. And I still get this error.
can anyone help me out to solve this? I'm on Windows 10.
Rails 5.0.2
Ruby 2.4.1
This just means there is another server running on Port 3000.
you can get around this and clear kill the running server manually
in the root of your application type:
cd tmp/pids
then you can check to see if there is a file in there called server.
if there is you can remove it. and you can start your server again on port 3000

No access to a rails server running behind a firewall

I am trying to run a ror application at a friend's home and the application is not reachable from the outside. Here is what we have tried.
The application has been created with
$ rails new <application name>
and started with
$ rails server
The development server starts and is reachable on http://localhost:3000
Next thing we have activated port forwarding on the router he uses to connect to the internet: we have mapped the external port 3000 to port 3000 on the internal host on which the rails server is running. When I try to open the page from the outside (with firefox) I get an error page: unable to conenct to host, the host may be down, try to connect later.
Things we have tried:
Changed port forwarding 80 -> 80
Installed and started Apache: the default Apache page is reachable.
Stopped Apache and started the rails server on port 80 (with sudo, otherwise it can't use port 80): the rails server is not reachable.
I have also checked the firewall of the machine running the rails server. The OS is ubuntu 12.04: the firewall (at least ufw) is not active. I can also connect to that machine using port 22 / ssh.
Summarizing:
rails server is accessible on port 3000 on local host
port forwarding works for ports 22 and 80 and both ssh server and apache server are reachable
rails server is NOT reachable on both port 80 and 3000 from the outside
The only thing I can think of is that rails might have a mechanism similar to Django's ALLOWED_HOSTS and that it refuses external requests because they are for a different host than localhost. However, I haven't found anything on this topic. Also, the application's log files do not show any connection attempt that was refused by the rails server.
So we are out of ideas. What should we check next?
Prior to Rails 4.2, the default for rails server was to bind to all interfaces. In Rails 4.2 this changed to only bind to 127.0.0.1 by default - there's nothing in the application logs because the socket is simply not listening to connection on other network interfaces.
To allow connections from another machine you need to use the -b option to bind to extra ip addresses, eg
rails s -b 0.0.0.0
to bind to all available ip addresses. You can of course replace 0.0.0.0 with one of your machine's actual ip addresses although you would of course have to change that invocation whenever your machine's ip address changed.

Can't connect to Rails server running on EC2 from public IP

I recently have been having a problem with my AWS EC2 instances. The problem is that I cannot hit my Rails servers via public IP, but I can hit localhost and the server will respond.
Here's what I'm doing:
Create new EC2 instance (t2.micro, ubuntu free tier)
Security group has port 22, 80, 3000 open to everyone (0.0.0.0)
SSH to EC2 instance, install rails (I've been using this to install)
Start rails server after install, it's running on port 3000
run "wget localhost:3000" and it returns index.html, yay!
go to my web browser, type in EC2 instance public IP and port 3000 (IP:3000), says it can't connect :(
kill rails server, restart it on port 80, wget works but can't connect via public IP
as a sanity check, I install nginx and run it, and can see the nginx start page on port 80 via public IP... so confused...
So I'm thinking it has something to do with how I'm installing Rails, but I've tried methods other than using that install script but am encountering the same problem... I've even tried creating an entirely new AWS account just in case I screwed up the settings in my original account but haven't had any luck. I have previously been able to get rails running on EC2 instances just fine (in fact I have EC2 instances using the same security group running on my AWS account right now and can hit those public IPs just fine), but am now just banging my head against the wall... any help would be greatly appreciated!
EDIT: For now, I've configured nginx to hit my rails server.... at least that works for now... although I'm still curious why I can't hit my rails server directly...
Check if rails listens on 0.0.0.0 or 127.0.0.1, default is to listen 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, rails server now listens on localhost instead of 0.0.0.0 by default. This should have minimal impact on the standard development workflow as both http://127.0.0.1:3000 and http://localhost:3000 will continue to work as before on your own machine.
If you are using 'rails server' and want to use the default port 3000 then 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 the port use the below to run the server:
sudo rails server -p 80 -b 0.0.0.0
You just access it as http://[public_ip].
I was running the rails server on default port 3000 on my AWS Ubuntu instance and had allowed this port in the security group, inbound section but still I was unable to access my application by using this.
http://public_ip:3000
I searched a lot and this answer helped me. Explaining the answer. We have to make firewall setting flexible so that our firewall allows port 3000.
You can use this command to check if this port is allowed on firewall or not.
$ sudo iptables -L | grep :3000
If you see nothing it means we have to allow it using this command.
$ sudo iptables -A INPUT -p tcp --dport 3000 -j ACCEPT
This worked for me to get my rails app access on port 3000.

Not ablet to bind address through webrick on rails on Ubuntu AMI

I have got rails setup on linux (ubuntu)ami. I am trying to bind the ip used to access linux ami but am not able to bind it." Cannot assign requested address - bind(2) (Errno::EADDRNOTAVAIL) "
Full rails setup seems to be fine.
Am missing something here. The exact need is to access the rails app through different pc.
Plz point me to some ref.
I may not be fully understanding your request but starting your rails server on a particular port:
rails s -p 3000 #rails 3
script/server -p 3000 #rails 2
Then you should be able to access this on a different pc by going to:
http://yourmachinename:3000
If new Pc is on the same network. Otherwise have a look at your firewall settings and open up port 3000 and point it to the local IP of your machine (you can get this from ifconfig). Then get the external IP of your local network and go to:
http://your.external.ip:3000/

cant do port forwarding ro my webrick server to access it from the net!

i am developing a facebook app and i am using for that facebooker plugin and webrick server.
i have configured correctly my router to froward ports to my machine for 2 ports (80 and 3000)
the apache server can be accessed from the net http://ip:80 amd the webrick server can http://ip:3000 ,
i dont understand why , please help me.
What IP address do you have WEBrick set to listen on? My guess is it could be set to “127.0.0.1” which would cause the problem you’re describing. If so, set it to “0.0.0.0” and see if that works. If you’re starting the server with script/server, you can specify the IP to bind to with the -b flag:
script/server webrick -b 0.0.0.0 -p 3000
You have to access it from another Network not in your network. Because your server is running on IP and your accessing machine is also connected to the same IP[because of port forwarding]. So it will not work in same network. You have to access it from different WAN IP Network.

Resources