How do I access my web application from a non-local machine? - ruby-on-rails

I have a Ruby on Rails application that I'm developing on my computer, which runs Ubuntu 10.04 LTS. I'd like to be able to access it from a remote computer for testing purposes. I've no idea how to proceed. Do I need to set up port forwarding? Virtual hosts? Can anyone point me to an article/tutorial/whatever that has information about how to do this?
Thanks!

If you want to run it using the server script, you can have it listen to a specific IP address like:
script/server -b 192.168.1.5
Substitute your machine's IP address that is accessible over your network. Then other hosts can get to the Rails app via e.g. http://192.168.1.5:3000.
If you mean you're behind a firewall or NAT gateway, then the question of how people outside of your firewall/NAT can get to your machine is another question entirely... something that probably belongs on superuser.com.

The best way I've found is to use http://www.tunnlr.com.

Related

Connect to rails server remotely from raspberry pi

I have ssh'd into my rasberry pi and built a rails application.
Now how do I load the rails app from another machine?
I have tried IP:port in a web browser, but this fails.
Can I use ssh from a web browser to load the rails server process?
Are there gems I need to install to do this?
Is there any good documentation that I have missed?
SOLUTION
use ngrok to tunnel https://medium.com/#karimbutt/using-ngrok-to-create-a-publicly-accessible-web-facing-raspberry-pi-server-35deef8c816a#.sraso7zar
Maybe the problem is with the IP address you're trying to use. Servers don't necessarily forward their public IP traffic to localhost automatically.
Perhaps you could configure the IP address somehow, I don't know (others might?). Alternatively, you have a use a "local tunnel" service like ngrok or localtunnel. What these do is create a public URL for your localhost (i.e. your "loopback" address), so anyone can access it.
I spoke with a Ngrok author via email. He ensured me that I shouldn't need to expect any downtime from the service or to have to manually restart it. Although keep in mind that if you're on the free plan, whenever you restart Ngrok you're going to get a different URL. He also described it as kind of like a "souped up SSH -R"

Accessing Ruby on Rails app from a Remote PC/Network - Windows 7 WEBrick

I am making an app using Rails on my home pc, and need to access the page from a computer at work.
I've found a few questions relating to this, but nothing like a process which I can follow as someone who doesn't have an awful lot of networking experience.
I know I need to open the port which I am using, but I can't seem to do this, as in windows firewall/allow programs I cant see the 'add port' button...
Am I right in thinking that the server should be set up to use default gateway as the IP ($bin/ rails server -p 192.168.0.1), and then use my public IP to access it from my work PC?
Any help/guidance is much appreciated!
Follow one of the port forwarding tutorials which are easily found online.
The IP you set up which looks like 192.168.0.12 or similar is the local IP address. Use this too access the website on the home network: 192.168.0.12:3000 if you forwarded port 3000.
$/bin/ rails s -b 192.168.0.12 -p 3000
Now, to access the server from external network, navigate to: http://your.public.ip.address:3000, which can be found by searching "what is my ip address" in Google.
There are some projects/software that help the job easier:
https://ngrok.com
http://localtunnel.me
http://proxylocal.com

Access Rails App Subdomains Through VirtualBox

I'm running a Windows 7 VirtualBox on my Ubuntu 13.10 machine where I have my rails app. I access my rails app through subdomains (i.e. subdomain1.lvh.me:3000) and I'm trying to access these same subdomains through my VB. I've read to change the host file but I haven't been able to make it work. Would I be using the Gateway IP or the IPv4 address?
The reason for me trying to accomplish this is to develop on my Ubuntu machine and test for IE issues on my VB without using paid third party websites to render my changes.
I think that if, for example, your ubuntu machine's ip address is 192.168.0.123, then it should suffice to have this line in your windows hosts file
192.168.0.123 subdomain1.lvh.me subdomain2.lvh.me subdomain3.lvh.me
Then on your windows vb you would access subdomain1.lvh.me:3000 like you say.
Have you done this? I don't know what you mean by " I've read to change the host file but I haven't been able to make it work. " What isn't working?

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!

Setup server for ruby on rails

working under linux server Centos remotly in local network, my rails server working there too. How can I enable remote web access? And if so how can I enable only couple of ip addresses for web access?
You should check on which addresses the server applications binds. If it has no external IP-Address then it wont be possible to access it directly from the internet. Then it is possible to use port forwarding to forward your application over your router. If you havent any access to the router you should ask the administrator of your network to forward it for you.
Another possibility is to plug a VLAN to a secound interface but you should think about security when you have a server that is connected to your NATed network and the internet directly!
if its only rails production server setup then you can try with this:
http://www.leonardteo.com/2012/11/install-ruby-on-rails-on-ubuntu-server/
it uses https://github.com/ballistiq/ruby-passenger-nginx-installer and they are maintaining the installer. I found its very helpful. it works like no-pain

Resources