How to Expose Local Rails App to the Public Internet

Using localtunnel gem

Step 1

Install NodeJS, if your machine does not have it installed.

Step 2

Install Localtunnel.

npm install -g localtunnel

Step 3

Start your rails app on your machine

rails s

Step 4

Request a tunnel to your local server:

lt --port 3000

Step 5

Copy the URL in the output:

your url is: https://cgoyfetijd.localtunnel.me

to access it from any machine. This gave the error:

504 Gateway Error (with nginx server version)

Due to security, since Rails 4.2 the local server is not exposed to the network.

Step 6

To fix this, start the server like this :

rails s -b 0.0.0.0

When this is accessed from another machine, the log file shows the error:

Cannot render console from 209.249.19.171! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255

Step 7

In development.rb:

config.web_console.whiny_requests = false

does not work. In development.rb, add:

config.web_console.whitelisted_ips = '209.249.19.171'

to allow that particular IP to connect remotely to your local Rails app. To whitelist the whole private network:

config.web_console.whitelisted_ips = '209.249.0.0/16'

You will now be able to access the Rails app running on machine from any machine connected to your network.

Using ngrok

Why ngrok?

  • Build webhook integrations with ease.
  • Run personal cloud services from your own private network.
  • Demo without deploying
  • Simplify mobile device testing

Step 1

Download ngrok and install it.

Step 2

Run your Rails app :

rails s -b 0.0.0.0

Step 3

Go to the directory where you extracted the zip file and run it.

./grok http 3000

Step 4

You can now access the Rails app from the URL displayed in the ngrok Forwarding section of the server output from anywhere. It will be something like: http://81ce07d0.ngrok.io.

London Underground Map

References


Related Articles


Ace the Technical Interview

  • Easily find the gaps in your knowledge
  • Get customized lessons based on where you are
  • Take consistent action everyday
  • Builtin accountability to keep you on track
  • You will solve bigger problems over time
  • Get the job of your dreams

Take the 30 Day Coding Skills Challenge

Gain confidence to attend the interview

No spam ever. Unsubscribe anytime.