Virtualbox rails server only accessible externally for some applications - ruby-on-rails

I have an xUbuntu(14.04) virtualBox(4.3.15) server running on Windows 7. I have a 2 sites on the server and when I run rails server for either application it can be accessed internally at localhost:3000 without issue. However, when I access one app externally from a browser on the windows machine at the [virtualbox ip]:3000 the site renders without issue and the other displays 'cannot connect'. Additionally I can ping [virtualbox ip]:3000 for the one site, but the other will receive no response. Just the [virtualbox ip] can be pinged successfully when either site has rails server running.
Both sites are Rails 4.2.0.rc2, Ruby 2.0.0, and WEBrick 1.3.1.
Is there something that needs to be setup specifically so that the 2nd site works?
Haven't been able to locate any differences between the two which might cause an issue.

Was able to determine what the issue was. The one app was starting on http://0.0.0.0:3000 which to my understanding means it is listening on all interfaces, while the other app was starting on http://localhost:3000. The localhost app was therefore not listening for external requests. The solution was to start the rails server with the following.
rails server -b 0.0.0.0
This binds the app to the 0.0.0.0 ip address and I can now access it outside of my virtualbox xUbuntu instance by using [vm ip address]:3000 as the url.

Related

Ruby on Rails - Starting server as a live website. [Linode]

I have made an account on Linode website and have a "linode" running. I have a server running using ruby on rails. The command I used is the following:
rails server --binding=<ip_adress>
The server starts up without issue. The question I have is why can't I visit the the side I created using my browser, just by putting the ip_address in the browser? The server logs display the following
Environment: development Listening on tcp:<ip_address>:3000
I can visit this ip_address on my browser but I need to add the ":3000" in the browser so I can view the site.
Shouldn't I be able to just visit the stand alone ip_address without entering ":3000"? I also wanted to say I am just learning ruby on rails as well.
I haven't tried anything more than described above
An IP address is a way to identify a machine on the internet.A port is a number assigned to uniquely identify a connection endpoint and to direct data to a specific service.
Therefore, your rails service is a combination of an IP address and a Port number. Since you can have different services running on the same machine at the same IP address.
HTTP has a default port of 80 which is what your browser will try to access when you don't provide a port.
Most likely, you will want a Reverse Proxy hosted at port 80 that forwards traffic to your rails app.
This post provides a better answer of how this works. https://superuser.com/questions/394078/how-can-i-map-a-domain-name-to-an-ip-address-and-port
Not Recommended
If you don't want to use a reverse proxy, you can host the rails server at port 80 itself.
rails server -p 80
Note that this requires you to have root permissions on the machine.

How do I make my ruby on rails app respond to external requests (visible to the public on the internet)?

Problem:
My rails app (on my local machine) only responds to requests sent from the same machine to localhost, 127.0.0.1, or my internal ip address. When I try to hit it using my internet ip or from any other machine, inside or outside of my network, it just times out. I'm on Mac OS 10.9.1, ruby 1.9.3, rails 4.0.0.
I've done a lot of searching but all I can find is problems where people didn't forward their ports or bind the right ip.
Here are the areas I've investigated:
Ports -
I've tried several different ports. I configured my router to forward every port I tried but got the same result. I thought maybe there was a problem with the router so I built a simple server in Java and bound all the same ports I was binding with my rails app. Sure enough, when I hit the Java app using my internet ip it worked just fine so the router/firewall/port forwarding isn't the problem. Also, I run an apache server on port 80 and that has never had any problems. I turned apache off and tried port 80 for my rails app but that didn't fix the problem.
Rails Server -
I started with WEBrick and I thought that perhaps there was some setting inside that blocked external requests. I searched google extensively and found nothing on that matter. Just to be safe I installed Thin and got the exact same result I did with WEBrick. One interesting thing is that when the rails server is started, the external request takes a long time to time-out, but the server console displays no output at all. However if I try to send the same request w/out starting the server at all it fails immediately.
User Permissions -
I started the server with root (i'm starting to just shoot in the dark here) and it had no effect.
Environment -
I was starting in development environment originally because I'm developing but just for fun I tried starting in production and it also made no difference.
PLEASE HELP ME SMART PEOPLE
Update:
I installed the app on my Ubuntu machine and it doesn't have this problem! So that suggests the problem may have something to do with Mac OS.
SOLVED:
It turns out that in the System Preferences -> Security & Privacy -> Firewall in Mac OS, it was somehow set to block incoming connections to Ruby 1.9.3. I must have accidentally set that some time ago.
The problem is you are probably trying to request the page from your local machine (or any computer on your local network, behind your firewall) to your public IP expecting a result... not unless you setup routes through your firewall for this (and not usually available on a consumer level router... linksys, dlink, etc)
So forward port 80 if you are using something like pow, or 3000 for web bricks default port to your local machine
Then have someone outside your local lan request your external (public) IP
This may be related: Rails 3.1 on Ubuntu 11.10 under VirtualBox very slow
Your mention of slowness combined with the use of webrick makes me think you've got some reverse-DNS lookup awfulness going on. A quick first step is hacking /etc/hosts to bypass this lookup.
The situation I dealt with on Ubuntu was solved in the short-term by hacking /etc/hosts. You could do this quick hack in order to see if it is indeed just webrick's reverse-DNS lookup. Edit /etc/hosts and add a line for the external user's IP address, something like this:
156.123.48.55 TestPerson
Replace the IP address with the tester's IP address. Since you said you can get the external request to hit an Apache server on port 80, you can grab their IP address from the Apache access logs if necessary, otherwise just ask the person testing.
You could also try a different web server, such as unicorn, which may help out. Add "gem unicorn-rails" to your Gemfile, run bundle install, and then (according to their docs), rails server will just use unicorn directly.
With any local server, you'll need to correctly configure port forwarding on your firewall. Like said by CaptChrisD, tests must be done by an external IP/browser (if you own a server, ssh on it, then w3m to test).
I already had same symptom (server started => timeout, server stopped => fail) and the origin was an issue with firewall configuration. I think it is your problem.
With MacOS, Pow is really awesome: installation is easy, no configuration required (no /etc/hosts…). Moreover, they give you a hook for external access to your virtualhosts (but you still need port forwarding on your firewall).
Otherwise, there is other solutions like Forward to do it without firewall configuration (30-days free trial).
Hope this helps!

Running Ruby on Rails app on server

I am using Aptana Studio 3 for development of ROR apps. I used run server command and it showed you can access your app on {http//0.0.0.0:3000/}, but when I try to access this URL, it tells me to check your Internet connection. I tried several other ports also but it is not working. I have created/modified the files necessary and migrated the database successfully too. Appreciate any help in running the app over the browser. I am currently using WeBrick Server.
so, in your title you say "on server". what does that mean? when you are running it on a different machine than your own, you need to use the address of that machine or it's domain name. keep in mind that firewall rules might prevent any connection to that server.
when you are ON the machine, via ssh for example, you can try calling the then "local" rails instance with curl http://localhost:3000/ to verify that it is running.

Access Rails Development Server From A Different Computer

I'm using webrick to develop my rails app on Mac OS X Lion. I'm trying to access the site from another computer (for testing). The internal IP of my computer is 10.1.10.100.
Accessing 10.1.10.100 displays the page served by the apache server running on my computer.
Accessing 10.1.10.100:3000 times out, both from my computer and from another computer on the same network. I can ping 10.1.10.100. From my computer, loaclhost:3000 displays the app.
Is there are firewall I need to open up on Mac OS X or some other setting that needs to be applied?
Thanks
While starting the webrick server specify the IP on which your rails application will run (10.1.10.100 in your case) using -b option, it binds Rails to the specified IP.
rails server -b 10.1.10.100 -p 3000

Rails server not working?

I'm following the first Ruby on Rails 3 tutorial from PeepCode and at around 27-29 minutes in, they have us start the Rails server. To the best of my knowledge, I have Rails (and Ruby) successfully installed.
When I run the command rails server (from Windows 7 Command Prompt per the instructions of the video), I get the message:
=> Booting WEBrick
=> Rails 3.1.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-12-02 18:37:57] INFO WEBrick 1.3.1
[2011-12-02 18:37:57] INFO ruby 1.9.3 (2011-10-30) [i386-mingw32]
[2011-12-02 18:37:57] INFO WEBrick::HTTPServer#start: pid=5584 port=3000
And it doesn't return to the prompt, indicating that it is running. Also, to me (and compared to the video), this looks like a successful message.
However, when I browse to the URL, http://0.0.0.0:3000, as directed by the video, I get an error (while the video opens to the default index page for Ruby). The error I get is:
Error 108 (net::ERR_ADDRESS_INVALID): Unknown error.
Since I'm using Google Chrome, it also says:
The webpage at http://0.0.0.0:3000/ might be temporarily down or it may have moved permanently to a new web address.
So, I was wondering how to fix this?
0.0.0.0 is the ip address that Webrick is binding to. It means 'listen on all interfaces'. In other words, you can connect to this application from the internal address (localhost or 127.0.0.1) as well as the external address on the network (192.168.1.x or 10.0.10.x or a domain name that resolves to an address this machine has on the network). The server doesn't care where the request comes from.
If, however, you started rails server with the '-b' or '--binding' option and told the server to bind to 127.0.0.1, the server would not respond to requests to the external interface. You could still use 127.0.0.1 or localhost but you could not connect to this server using it's external ip address locally or from another machine.
Going to http:// 0.0.0.0:3000 works on my Linux system and most likely the screencast you were watching was using a mac which would also work. My guess is that 0.0.0.0 isn't supported on Windows.
Just use localhost if you are on the box or the ip address of the box if you are accessing it from another machine. That is what I do, even when I'm running a machine that understands 0.0.0.0.
You can start the server with this command:
rails server -b localhost
But as a lazy typist, in my .bash_aliases, I have this alias
alias rs='r s -b localhost'
With the alias, I can start the server with just:
rs

Resources