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

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/

Related

Puma is not working on server

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

Connecting rails server from local machine to network

I have made a rails application using 4.2.0 in my local Ubuntu machine. I want to deploy that application to local network of my campus. How can I do that?
I checked my ip from ifconfig, and deployed the webrick server via binding that ip and different ports too,
rails server -b my_ip -p port
the console says that the application is running in that ip and port but when I am trying to connect it via my browser, I get service timout error. Can anybody suggest me a method to do that?
Binding to 0.0.0.0 tells the service to bind to all IP addresses on your machine. Rails server used to do this by default, but with 4.2 changed to binding only to localhost.
Basically if it's only bound to localhost then it will only respond locally to either localhost or 127.0.0.1 which can't work through a DNS service because it's not a public IP address.
When you use 0.0.0.0 it will bind to localhost and to your routable IP address.
Use rails s -b 0.0.0.0

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.

Access Webrick Rails Server from local network

Hello i am trying to access my Webrick rails server that i started on my ubuntu to my windows 7 pc locally. I checked on ifconfig in my virtual box and used the inet:10.0.2.15 when i run my rails server and also used port 80 like this:
rails server -b 10.0.2.15 -p 80
It didn't gave me an error in the terminal but when i try to go to 10.0.2.15 on my windows browser, it says it can't connect. I tried disabling the firewall in windows but still wont work. Thank you.
Choose another network type for your VM ubuntu. I suggest the Bridged Network. Reboot vm, it should obtain ip in same network as your windows host (example 192.168.0.XXX). Then you will be able reach your rails server from network At any port 80 or 3000.
Can you share your ubuntu with the vm, via the apache server too? is that started? In macs you have to enable web sharing (or something similar to that wording). ON ubuntu what happens when you do localhost:80... if i recall it should say it works! or something like that.

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