deploy ruby on rails 5 on AWS - ruby-on-rails

I made an environment on Cloud9 on AWS, then made a folder named "ruby_projects", then inside that folder, I ran the command:
rails new todolist
then from inside the todolist folder, I ran
rails s
In the share button on the top right corner of the environment, I opened the application link which is 35.162.65.187, but instead of saying "you are on rails" it says:
Oops
Error: 1 validation error detected: Value '35.162.65.187' at 'envir..

For changing port on AWS you can do something like this:
sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3000
For local machine:
rails server -p 80
But, Phlip absolutely right - you should learn rails on local machine with development environment. Step by step.

You have two ways to preview applications on AWS Cloud9--through the preview URL (from clicking the Preview button) and from the public IP for the host (AKA the sharing URL). The Preview URL is a bit easier to run, but has a few limitations. Specifically:
You need to serve your content on 127.0.0.1:8080 (ports 8081 and 8082 work as well but have to be specified)
You can only access the URL when you are currently logged into the IDE and have the IDE open.
Only IAM users with access to the IDE can access the Preview URL. For instance, this won't work if you are calling this endpoint from another program.
You can read more about the Preview URL here: https://docs.aws.amazon.com/cloud9/latest/user-guide/app-preview.html#app-preview-preview-app
If you need to share this to people who don't have access to the IDE or you need to access the endpoint through a different program, you'll want to use the Sharing URL. This requires a bit of additional configuration, specifically, you'll have to:
Create a security group for the host that opens your selected ports to the main internet
Run the server through 0.0.0.0 instead of 127.0.0.1
You can see how to do this here: https://docs.aws.amazon.com/cloud9/latest/user-guide/app-preview.html#app-preview-share

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.

ClearML SSH port forwarding fileserver not available in WEB Ui

Trying to use clearml-server on own Ubuntu 18.04.5 with SSH Port Forwarding and not beeing able to see my debug samples.
My setup:
ClearML server on hostA
SSH Tunnel connections to access Web App from working machine via localhost:18080
Web App: ssh -N -L 18081:127.0.0.1:8081 user#hostA
Fileserver: ssh -N -L 18081:127.0.0.1:8081 user#hostA
In Web App under Task->Results->Debug Samples the Images are still refrenced by localhost:8081
Where can I set the fileserver URL to be localhost:18081 in Web App?
I tried ~/clearml.conf, but this did not work ( I think it is for my python script ).
Disclaimer: I'm a member of the ClearML team (formerly Trains)
In ClearML, debug images' URL is registered once they are uploaded to the fileserver. The WebApp doesn't actually decide on the URL for each debug image, but rather obtains it for each debug image from the server. This allows you to potentially upload debug images to a variety of storage targets, ClearML File Server simply being the most convenient, built-in option.
So, the WebApp will always look for localhost:8008 for debug images that have already been uploaded to the fileserver and contain localhost:8080 in their URL.
A possible solution is to simply add another tunnel in the form of ssh -N -L 8081:127.0.0.1:8081 user#hostA.
For future experiments, you can choose to keep using 8081 (and keep using this new tunnel), or to change the default fileserver URL in clearml.conf to point to port localhost:18081, assuming you're running your experiments from the same machine where the tunnel to 18081 exists.

Run Rails application in AWS Cloud9

Recently I migrated my workspace from the old Cloud9 to AWS Cloud9. Now I can no longer run my application. I'm hoping somebody on Stack Overflow might have an idea what the problem is because AWS' help forums and documentations skip past the parts I'm missing.
The "Run" button tries run the last file that I was viewing and editing, rather than my application as a whole.
So I try to start it running in the terminal with "rails s -b $IP -p $PORT". I get this line:
Listening on tcp://127.0.0.1:8080
So the program should be running, right? But the green "Run" button is now disabled, and I don't get the spinning icon in my terminal window that I used to get with old Cloud9.
Next I try getting the application's url from the "Share" menu, which is:
18.212.63.5
When I try to navigate to this url in another window, I get an error
ERR_CONNECTION_TIMED_OUT
When I try to "Preview Running Application" with the IDE, I get the error
66af0558a4b44f8bb019cb5628f6b28f.vfs.cloud9.us-east-1.amazonaws.com refused to connect.
In related news, I'm highly frustrated with AWS for a lot of other reasons. Should I consider switching to a different IDE? Or keep trying to learn this one?
Thank you in advance for any insight.
See also https://forums.aws.amazon.com/thread.jspa?messageID=899522, which provides a set of diagnostic commands that you can run from a terminal session in the AWS Cloud9 IDE for your development environment that can output the incoming traffic rules for the environment's associated Amazon EC2 instance's security group and network ACL. These traffic rules need to allow incoming traffic for the correct protocol and port.
I had what I believe was a similar problem. The preview won't show if the app is being served over http, rather than https:
https://docs.aws.amazon.com/cloud9/latest/user-guide/troubleshooting.html#troubleshooting-app-preview-http
A simple workaround here is just to remove the 's' from the amazonaws.com URL listed in the 'refused to connect' error, and then press the button to preview the application in a browser tab.
Also note that on AWS C9 you shouldn't need
rails s -b $IP -p $PORT
It should usually be enough to do
rails server
(though check that, for example, your puma.rb file is set to run on port 8080 rather than 3000)

Requests through another machine

Is it possible to make requests for example with Savon through something like ssh-tunnel. I can run this stuff from my stage server whose IP is whitelisted in the service I'm sending requests to. But of course I want to do the development on my computer :P so is there any option to do that? I've already tried savon's proxy: option in many combinations such as
proxy: "http://name:password#my_stage_server.com"
etc. I'm using Ruby on Rails.
SSH tunnels are the way to go. They are easy to set up, use this in one terminal session:
ssh -L 8080:servicehost:80 myuser#stagingserver
Once established, leave it open. It'll open port 8080 on your localhost as a tunnel to the TCP service at host:443. Point savon to http://localhost:8080/some/url/to/service to access the service running on http://servicehost/some/url/to/service.
If you need this frequently, it's convenient to add it to your ssh config file, which is located at ~/.ssh/config. It's a plain text file, the example above would look like this:
Host staging
HostName hostname.domain
LocalForward 8080 servicehost:80
User myuser
With this configuration you can open the tunnel by simply issuing ssh staging. There are more options you could set, please refer to the MAN page for details.
Hostname resolution
Keep in mind that the hostname servicehost must be resolvable from your staging server, not your development machine. You can use IP addresses, too.

Cannot access http://localhost:3000

I am trying to learn Ruby on Rails, I have followed the instructions from this page to get rails installed on my PC.
I am also trying to follow this webcast to try and learn the language and framework. Everything is working so far, apart from the fact that I cannot access
http://localhost:3000
http://0.0.0.0:3000
http://127.0.0.1:3000, or
http://<actual IP address>:3000
locally. If I try the from another PC on my network then it works great. I have tried in Chrome, Firefox and IE7 but none work.
Has anyone else had this problem?
EDIT: Typical!! It's started working now. I have no idea why, I am typing the exact same address in to the address bar and it now works. But only if I use http://127.0.0.1:3000, localhost doesn't work. I do run IIS ASP.NET/ASP websites on this machine, and they work fine with localhost.
EDIT 2: If I trying pinging localhost it actually says
Reply from ::1: time<1ms
0.0.0.0 yields...
PING: transmit failed, error code 1214
only 127.0.0.1 seems to work. I did have IPv6 turned on, so I've disabled that and will try again tomorrow to see if a reboot helps.
I had this issue as well with Vagrant. The secret is to run
bin/rails server -b 0.0.0.0
What 0.0.0.0 means is to listen to all interfaces, not just on localhost. The alternative is to SSH into the vagrant machine with a SOCKS proxy.
ssh -C -D 8080 vagrant#localhost
Open up your Internet explorer proxy settings and set the SOCKS v5 proxy to port 8080.
In order to access http://localhost:3000 you need to run the local Rails server in a terminal window:
$ rails server
This is described in this section of the Rails Tutorial book.
Note: I am the presenter of the screencasts in question.
Can you telnet to the port? Try:
telnet localhost 3000
That should tell you if the ports unavailable at the TCP level, or whether something's going on at the HTTP level.
Ping might not work if ICMP is disabled, which could be completely unrelated to your issue.
Also, try looking in your hosts file for any redirections:
c:\Windows\System32\drivers\etc\hosts
One way is to do the simple
rails s
Another (more specifically) is
rails start localhost 0.0.0.0
or
rails start 0.0.0.0
another way is
rails s 0.0.0.0
all of these works
I had an epic issue with my System Path (Environmental Variable) not being set properly.
Simple copy paste job, unplugged the 1 week stalled Ruby installation.
Control Panel > System > Advanced tab > Environment Variables > System variables > Path... Edit...
Make sure it contains these paths (among others)...
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem
I had your same identical problem. You have simply to run
$ rails server
from inside the folder of your application, not outside...so, if you have your application in
C:\Sites\myapp\blog
and blog is the folder where live your app, the command has to be prompted from here. Launching it from myapp folder won't work.
Are you possibly using a proxy but haven't listed localhost as proxy exception?
Have you tried disabling your firewall? They can cause pesky problems at times.

Resources