After installing rails, how to run rails server on amazon ec2 instance? - ruby-on-rails

I installed rails on an instance on amazon AMI. I installed all the dependencies for rails. I even copied the code through scp. When i ssh to the instance i ran
rails s
The server is running. How can I view it from the browser?
from the Public DNS???

In summary, sure that your security group have a rule for TCP 3000.Then, you can use the Public DNS:
rails server -b ec2-XX-XX-XX-XX.us-west-2.compute.amazonaws.com -p 3000
And access to: ec2-XX-XX-XX-XX.us-west-2.compute.amazonaws.com:3000
This works for me.

Your amazon ec2 instance has a public ip address and domain name, see
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html
use this domain name as the URL in your browser.
You will also have to set inbound traffic / port connections in the security group of the instance.
A word of warning: with "rails s" you are starting webrick, a server that is only meant to be used in development. You probably should use a production server like apache + mod_passenger.
For more advanced usage of ec2 and ruby on rails see
http://railscasts.com/episodes/347-rubber-and-amazon-ec2?view=asciicast

move to folder from rails aplication and typerails s -b 0.0.0.0

Related

Use one elasticsearch server of rails application in another rails application

My rails application is running using four ec2 instances. When user hit rails application using url, rails application will be serve to the user using any one of four ec2 instance using ELB.
Elasticsearch server is installed on one of the rails server. How i can use same elasticsearch server which is installed on one server for rest of three rails servers also for searching?
I am using the internal (10.x.x.x) address for connecting to elasticsearch.
Elasticsearch::Model.client = Elasticsearch::Client.new(host:'10.x.x.x',port:9200)
As long as you set your inbound rules right you can connect to your elasticsearch instance from any ec2 host.
Make sure that elasticsearch listens on 10.x.x.x and not only on 127.0.0.1.
put network.host: _site_ in elasticsearch.yml

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.

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

What influences whether "rails server" on :3000 is accessible remotely?

Here are two GitHub repositories:
https://github.com/maarxx/aws1T4Z
https://github.com/maarxx/aws2T4Z
Each one basically* contains the default boilerplate program that gets generated when you type "rails new APP_NAME" into a terminal.
I am deploying them identically to a remote server (specifically an EC2 instance in AWS).
For the first one, the "rails server" on port 3000 is accessible remotely.
For the second one, the "rails server" on port 3000 is NOT accessible remotely.
Would anyone be able to shed some light as to why this is the case?
To provide some background:
The first was generated in May 2014, the second was generated in March 2015.
*The first I might've tinkered with slightly, but I cannot remember what I changed (this is the driver of my question). The second is unmodified.
You may notice that your earlier project (rails 4.1.1) prints something like this at bootup:
=> Rails 4.1.1 application starting in development on http://0.0.0.0:3000
Whereas, the later project (rails 4.2.0) prints something like:
=> Rails 4.2.0 application starting in development on http://localhost:3000
The difference here is that the first project is listening on 0.0.0.0 (any ip) and the second is listening on localhost (127.0.0.1), which is only accessible from localhost.
You can bind your rails server to any ip with the -b option:
rails server -b 0.0.0.0
See http://guides.rubyonrails.org/4_2_release_notes.html#default-host-for-rails-server for more information on the change and How to change the default binding ip of Rails 4.2 development server? for how to change the default.

Domain setting using ruby rails

I am planning to have a web application.
To do so, I studied about ruby and ruby on rails. I am using linux server from amazon clouding system.
I bought a domain from godday, and I put the IP address on DNS setting. When I run 'rails s' command, I can connect to the wep page through port 3000 in such a way that domain.com:3000. However, I cannot directly connect to domain.com. How can I my domain works without port 3000?
And Do I have to run 'rails s' every time to make the wep page work? Actually I tried to use 'rails s &' to make it run in background. But it fails. How can I make the server run even though I am not connected to the linux server?
Thank you!
usually you use rails s just in development. there are quite a few ruby web servers you can choose from for your production environment: puma, passenger or unicorn to name a few.
of course all of them have their own tutorials how to set them up. for starters, i'd go with with passenger because it's integrated with nginx and apache and easily set up.
You need to specify a port, if you don't see the port it can be either 80 (http) or 443 (https).
rails server -p 80
On linux you have to be root to bind to port less than 1000, so just append sudo in front.

Resources