How to use ngrok with puma-dev rails server - ruby-on-rails

My rails app is spin up using puma-dev on Ubuntu.
I'm using puma-dev command to start my app (in foreground) and then access the rails app using
https://app.test:9283.
As the puma-dev is running in the foreground I have to use the port 9283 to access the port.
Now I want to access the rails app on remote machines like a mobile device or other PC. So have to use the ngrok to do so. I have installed ngrok in my ubuntu but I'm not able to access my localhost setup running on https://app.test:9283 using ngrok. Any help would be appreciated!
NOTE: When I use ./ngrok http 80 it successfully redirects me to localhost:80 which means ngrok is working properly.

With puma-dev it is necessary to include the -host-header argument, like so:
./ngrok http -host-header=app.test 9283

you have to bind the ngrok server with the same port as rails server ./ngrok http 9283

You need "local-leg HTTPS."
./ngrok http https://app.test:9283

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.

Serving localhost rails application externally https

I am currently running a rails application on my local machine as the backend api for a hobby web application (have too many sql rows and dont want to pay for it).
I already figured out how to forward my port and access the api through http://[myexternalipaddress]:8080/api/etc.... from the external internet.
This is working fine, but i want to be able to serve this end point through https instead so my users dont get security warnings. I did some research, but I am confused what I need to do next. Is the https serving done via my rails configuration, or some other method?
here is the command I use to start my rails server:
rails s --binding=0.0.0.0 -p 8080
You can use ngrok and expose your local server
on mac you can install it with brew
$ brew cask install ngrok
$ ngrok http 3000
this will give you url like https://xxyyzz.ngrok.io to access it publicly

Why Puma listen on 'tcp://localhost:3000' instead of 'http://localhost:3000'

I'm a Rails developer. There was a time I want to debug my Rails application runing in local on the mobile. So I tried to update my '/etc/hosts' to add the LAN ip(192.168.0.18) to localhost and make sure your laptop and mobile are connecting to the same LAN.
If I start my Rails application with 'Webwrick', it will listen on 'http://localhost:3000', then everything work well
But if I start my Rails application with 'Puma', it will listen on 'tcp://localhost:3000', and then I can't access the server by my LAN ip and port(192.168.0.18:3000)
The HTTP protocol works on top of TCP, HTTP adds format to the raw TCP, so it kind of means the same thing.
Given that Webrick and Puma are different HTTP servers, they may refer to the same thing in different ways.
I hope this will be the worst of your problems during your journey with Rails! Enjoy!
Try running this command: rails s -b 0.0.0.0 -p 3000

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.

Rails Https redirect to http

I have hosted my website http://www.example.com, and it works fine.
when I try to access it by https://www.example.com, my browser says it is unable to connect?
Is this normal? (Is it a DNS issue or a rails app)
This probably isn't a Rails issue, but it's hard to say without more information. The most likely explanation is that your server probably isn't configured to have port 443 open, which is the default port for https connections.
If you are on Amazon EC2, you'll need to manually open port 443 in the EC2 security group configuration.

Resources