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

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.

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"

How to Deploy Rails App to AWS

I am trying to host a Rails app in AWS cloud where I have an EC2 instance and apache and mysql . Here I have uploaded my app but I am unable to bind it with IP. For a testing I am using this blog post https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-unicorn-and-nginx-on-ubuntu-14-04 as a reference .
When I am trying to run this command :
RAILS_ENV=production rails server --binding=server_public_IP
I am getting this error :
/home/ubuntu/.rbenv/versions/2.2.3/lib/ruby/2.2.0/socket.rb:206:in `bind': Cannot assign requested address - bind(2) for 52.24.103.139:3000 (Errno::EADDRNOTAVAIL)
Is there anyone help me understand what is this problem and how to deploy it on AWS apache .
In AWS the machine is not directly assigned the IP, i.e. it is routed using NAT. hence you can not use the public IP to start your rails server directly.
To start server just boot it without the binding parameter rails s production
Or you can use 0.0.0.0 to bind your server, this will start your rails on all the interfaces.
Tip: For production you should ideally server using some web server like nginx/apache using passenger/unicorn
Looking from error it says it cannot bind with ipadd 52.24.103.139:3000
What I would suggest it to open a 'custom TCP port 3000' and try running the same thing again.
May be your app is working on port 3000 not 80.
Hope that helps.

What is localhost:8000 as used in Codecademy (for AngularJS and Ruby on Rails tutorials)?

I want to know what is this: localhost:8000, found in Codecademy tutorials for AngularJS and Ruby on Rails. I even installed Apache 2, but to work with it I need to dial: http://localhost/. While working on some html files, I often come across Firefox's Inspect Element where a section is to mention localhost and its number like this: localhost:8000. I want to know what's this and can I use it to access my host from my android device or some other PC as we do access Codecademy's localhost to learn AngularJS and Ruby on Rails. Pls help. Thanks in advance. :-)
Localhost is the loopback-address of your pc. The IP-address behind it is 127.0.0.1. With localhost, it is possible to simulate a web-server environment and it is mostly used to simulate running web-applications as if they are running on a webserver. :8000 stands for the port-number on which the browser connects to the server. This is because the application runs (in this case) on port 8000 of the server. So it is not enough to just install Apache 2 and surf to http://localhost/ you have to configure Apache so that it runs your web-application on the desired port. The port-number itself has no special meaning. The different ports are just a part of the url so the browser knows on which port it has to connect. Some protocols use default ports. (e.g. HTTP will always connect to port 80, unless your specify another port in your webbrowser)
I'm sure a lot of people can explain it much better, but here is a begin.
More info about running ruby on rails on an Apache webserver:
How can i run a ruby on rails project on apache server?
How to setup Ruby on Rails Hosting using Apache, from Development to Production
EDIT: Technically, the whole 127.0.0.0/8 address block is reserved for loopback purposes. The default one, configurged in hosts.txt is 127.0.0.1 and the most famous.

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.

Accessing Ruby Server on amazon instance from my browser

I have started the Ruby on Rails tutorial and am on my first app. I did all of this on an instance I have on amazon web service (aws). A while ago I installed apache on there so when I put in the public address (port 80) it tells me 'It works'. I want to access this server from my web browser at home.
However when I put in the server address :3000 (the port the app should be running at) I get nothing. Do I need to tell the box to open port 3000 or something of the like?
You need to open the instance's security group to accept traffic on port 3000. Check out the docs for more information.

Resources