running ruby on rails in virtual box debian instanz - ruby-on-rails

my host system is a windows 8.1 system
there i've running a debian 7 vm in virtual box.
I've created a new Ruby on Rails project and started the server. Server starts properly and listen on port 3000
So i added a port forwarding rule in virtual box for this port
But now when I try to reach 127.0.0.1:3333 from my host got an error page not found.
Is there something to look at?

when starting your server, use sudo rails server --binding=0.0.0.0

Related

Rails server refuses to connect in browser

I'm just trying to run my server locally. I'm on Windows and using Ruby on Rails on Windows is a pain, so I am using Vagrant. I am doing all of these commands from my Vagrant shell.
I've tried rails s and rails s -b 0.0.0.0. Both give me OK responses in the terminal:
=> Rails 5.2.3 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.1 (ruby 2.6.1-p33), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
However, when I go to localhost:3000 in my browser, it gives me:
This site can't be reached.
localhost refused to connect.
When I tried to curl http://localhost:3000 get:
curl: (7) Failed to connect to localhost port 3000: Connection refused
I also have the following line of code in my Vagrantfile:
config.vm.network "forwarded_port", guest: 3000, host: 3000
Really don't know what to do next. Right now, I am installing Ubuntu ISO file (will be done in 5 hours, so that's quite a bit of time) to create a VirtualBox instance as backup if this doesn't work. Hoping I can find a fix for this.
I would like to suggest you docker. Docker is not new, it was released in 2012 and since then has become one of the fastest-growing technologies in web development and devops.
Some of the advantages you will have if you start using it:
Reproducibility: A docker container is guaranteed to be identical on any system that can run docker and having a simple file you (and your team members) can run the system with the same specs really fast on another environment.
Isolation: Dependencies or settings within a container will not affect any installations or configurations on your computer.
Hub: You have thousands of well maintained images available including ruby and you can use them for faster experiment and get in the stuff that mater.
Docker is not vagrant, is a lot more and much more powerful.
Easy image upgrades: because images are versioned, it's a matter of to change a single tag.
Happy codding with the whale!
The key thing here is "localhost" on your Vagrant box and "localhost" on your machine are two different things. The port forwarding can often fix this, but if you have two Vagrant machines using the same port you may be sending traffic to the wrong one.
It's often better to get the Vagrant machine's IP and connect to that directly. If that IP keeps changing, you can lock it down:
config.vm.network "private_network", ip: "172.30.1.5"
Then you connect to http://172.130.1.5:3000/ predictably.
Resolved by running Ruby on Rails on UBUNTU VirtualBox machine.

Rails application can't reach remote PostgreSQL server (proxy, VirtualBox)

I have a Windows 7 PC with Forefront TMG proxy. There is a VirtualBox virtual machine installed with Ubuntu 16.04 (64-bit) guest OS. I'm not a seasoned Unix-user, so I tried to configure Ubuntu's network through GUI window.
After several tries I wound up with these settings:
https://i.stack.imgur.com/in4yR.jpg
All works fine now. I can use browser and git and do various network stuff. But!
I have a Rails application, which uses a remote PostgreSQL database. When I start my Rails server, it throws this exception:
Puma caught this error: could not connect to server: Network is unreachable
Is the server running on host "this_is_the_host_url" and accepting
TCP/IP connections on port 5432?
(PG:ConnectionBad)
This applications works fine on the other PC with similar Windows 7 and VB Ubuntu, but without a proxy. Also I tried to reach the remote DB-server from my host Win7 with PGAdmin - all works fine, even with proxy. The issue is somewhere between my Ubuntu guest OS and my Windows host OS.
Should I configure proxy settings in Ubuntu in a different way?
Any other way to resolve this issue?
Traceroute shows this:
1 10.0.2.2 (10.0.2.2) 0.638 ms 0.577 ms 0.549 ms
2 10.0.2.2 (10.0.2.2) 29.369 ms !N 53.000 ms !N 75.644 !N
As I can get it, 10.0.2.2 is my host OS ip.
I searched through the web, but all I could get belongs to the opposite side: to reach to the proxied VB Ubuntu, not from it.

How to connect rails application(locally run on zeus) in another machine using IP?

I am using two rails applications, running both with rails s and zeus s -p3001 locally. When I am trying to run my application in another machine, the server started with webbrick is running fine on another system but couldnot run zeus. PLease help me out.
I just gave the url in browser 192.168.1.111:3000 (running). And
`192.168.1.111:3001` (server not found).
I tried zeus s -b 192.168.1.111:3001 but didn't help me.
The problem is, that the zeus bind to the local address (127.0.0.1) prohibiting connections from remove hosts. The proper solution would be to setup the reverse proxy using apache2 or nginx.
http://glasz.org/2013/10/25/reverse-proxy-a-rails-app.html
https://www.digitalocean.com/community/tutorials/how-to-deploy-rails-apps-using-unicorn-and-nginx-on-centos-6-5
Alternatively you may also want to use firewall to redirect requests.
http://forum.slicehost.com/index.php?p=/discussion/2497/iptables-redirect-port-80-to-port-8080/p1
But a quick and dirty solution is to use SSH port forwarding like this:
Start zeus on remote machine on port 3000
On local machine
local-machine$ ssh -L 3001:localhost:3000 remote-machine
On local machine: Connect to localhost:3001 instead of to remote-machine:3000
http://blog.trackets.com/2014/05/17/ssh-tunnel-local-and-remote-port-forwarding-explained-with-examples.html

Accessing rails sever on a virtual machine from host machine

I've got Ubuntu (the newest version) running as a virtual machine on Windows 7 Pro, using VMware.
My question is, can I make the rails sever acessible to windows while the virtual machine is running?
So, for example, if I type on my Windows browser http://localhost:3000 I would get the rails sever?
Also, can I make it acessible to computers from the outside, so if someone would type
myipaddress:3000 he would be able to acess the sever as a client?
I hope this is clear.
There are a lot of "ifs" here, but it should "just work".
In Linux, find the IP address of your virtual machine.
$ /sbin/ifconfig
You're looking for a section that is probably labelled "eth0" and in that "inet addr".
Using that address with port 3000 from your Windows host should work fine. If not, post the specific problem that you're seeing, including any logs you can find or info on any firewalls you have running on your Linux client.

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

Resources