Can't Access Rails Server on EC2 Instance from Public IP - ruby-on-rails

I have rails running on an Amazon EC2 instance but I'm having trouble accessing my rails server (port 3000) from public IPs. This was working as recently as last week but today when I started up my rails server I was unable to get a response from an outside IP. Even when I created a brand new rails project I was not able to access the server once I had started it.
Despite this I can access the Apache server by going through port 80. Moreover SSL continues to work.
I have already
ensured that the port 3000 is open on my security group in the Amazon EC2 console
checked my iptables on the Amazon instance. There are no rules and the default for the INPUT chain is to accept packets.
banged my head against a wall.
Does anyone have any ideas?

Did you verify the port 3000 is opened for every IPs addresses and not only for your workplace's IP?
Also, your Amazon EC2 virtual machine's IP could have changed.

Related

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

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.

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.

Site being cloned or deploy to domain I don't own

I'm deploying a Rails app to EC2 using Elastic Beanstalk. I just found out, while doing a search in google that whenever I deploy to my domain, my site seems to also get deployed to a domain I don't own. I use Route 53 for my DNS as well.
Has anyone ever run into this situation or have any idea what might be happening here?
It could be a simple DNS issue. Someone's DNS A record is pointing to the ip address of your EC2 instance
Amazon recycles ip addresses. It is possible that your current ip address was allocated to someone else earlier, and they have not deleted their DNS entry when releasing the ip address.
you can run ping command to confirm both domain names resolve to same ip address
ping domain1.com
ping domain2.com

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