webrick server stops after putty is disconnected - ruby-on-rails

I am new to programming and Ruby on rails (and stackoverflow as well :) . I have setup an ubuntu test server. I can access my ruby application over internet which is configured on this server. I am using weBrick as webserver for my application.
I am able to start the Webrick server using command:
rails s -b ip address -p portnumber
through putty and then access my application over internet.
The problem is: when i close putty session after that I cannot access my application. the error that appears in chrome browser is
connection refused
It appears to me that the webserver(webrick) shutsdown when I disconnect putty which should not happen. Please correct me where ever I am interpreting the scenario incorrectly.
Also please let me know what additional information is required to seek the resolution. Thanks

Related

Can’t access rails app on Mac host from VMware Fusion Guest

I’m probably doing something stupid here, but....
I can’t access a rails app running on my Mac from a Windows 10 VM. I have set the network adapter to "Share with My Mac". I can access a PHP site running on my mac via http://[my-machine-name].local or http://[my-ip-address]. But if I specify port 3000 to view my rails app I get an error message (to the effect that [my-ip-address] refused to connect) even though the app is running. I don’t know if this is an issue at the Mac end (though my firewall is off for testing), the windows end, or to do with my VMWare network adapter setting. Any assistance gratefully received
Peter
Just use the -b flag while running your rails app like rails server -b 0.0.0.0:3000 so it gets bound to the whole network interfaces and it can be accessed from outside

Virtualbox rails server only accessible externally for some applications

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.

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.

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

Cannot access http://localhost:3000

I am trying to learn Ruby on Rails, I have followed the instructions from this page to get rails installed on my PC.
I am also trying to follow this webcast to try and learn the language and framework. Everything is working so far, apart from the fact that I cannot access
http://localhost:3000
http://0.0.0.0:3000
http://127.0.0.1:3000, or
http://<actual IP address>:3000
locally. If I try the from another PC on my network then it works great. I have tried in Chrome, Firefox and IE7 but none work.
Has anyone else had this problem?
EDIT: Typical!! It's started working now. I have no idea why, I am typing the exact same address in to the address bar and it now works. But only if I use http://127.0.0.1:3000, localhost doesn't work. I do run IIS ASP.NET/ASP websites on this machine, and they work fine with localhost.
EDIT 2: If I trying pinging localhost it actually says
Reply from ::1: time<1ms
0.0.0.0 yields...
PING: transmit failed, error code 1214
only 127.0.0.1 seems to work. I did have IPv6 turned on, so I've disabled that and will try again tomorrow to see if a reboot helps.
I had this issue as well with Vagrant. The secret is to run
bin/rails server -b 0.0.0.0
What 0.0.0.0 means is to listen to all interfaces, not just on localhost. The alternative is to SSH into the vagrant machine with a SOCKS proxy.
ssh -C -D 8080 vagrant#localhost
Open up your Internet explorer proxy settings and set the SOCKS v5 proxy to port 8080.
In order to access http://localhost:3000 you need to run the local Rails server in a terminal window:
$ rails server
This is described in this section of the Rails Tutorial book.
Note: I am the presenter of the screencasts in question.
Can you telnet to the port? Try:
telnet localhost 3000
That should tell you if the ports unavailable at the TCP level, or whether something's going on at the HTTP level.
Ping might not work if ICMP is disabled, which could be completely unrelated to your issue.
Also, try looking in your hosts file for any redirections:
c:\Windows\System32\drivers\etc\hosts
One way is to do the simple
rails s
Another (more specifically) is
rails start localhost 0.0.0.0
or
rails start 0.0.0.0
another way is
rails s 0.0.0.0
all of these works
I had an epic issue with my System Path (Environmental Variable) not being set properly.
Simple copy paste job, unplugged the 1 week stalled Ruby installation.
Control Panel > System > Advanced tab > Environment Variables > System variables > Path... Edit...
Make sure it contains these paths (among others)...
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem
I had your same identical problem. You have simply to run
$ rails server
from inside the folder of your application, not outside...so, if you have your application in
C:\Sites\myapp\blog
and blog is the folder where live your app, the command has to be prompted from here. Launching it from myapp folder won't work.
Are you possibly using a proxy but haven't listed localhost as proxy exception?
Have you tried disabling your firewall? They can cause pesky problems at times.

Resources