0

I deployed my ruby on rails project on a different virtual instance, and I changed the binding IP to an external floating IP by append this code to /config/boot.rb:

require 'rails/commands/server'
module Rails
  class Server
    def default_options
      super.merge(Host:  '199.116.235.154', Port: 3000)
    end
  end
end

and it can also be find in this answer. However, when I start the server by: rails s, I got this error:

> /home/ubuntu/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-3.2.0/lib/puma/binder.rb:240:in
> `initialize': Cannot assign requested address - bind(2) for
> "199.116.235.154" port 3000

I know it is because 199.116.235.154 was an external host, so puma won't grant the access for me. And when I change it to internal IP: 10.2.3.52, it runs, but I can't target 10.2.3.52 from my phone browser or other computer. So, is there any way for me to make the public 199.116.235.154 IP work for me?

Also, my frontend was built in a different directory by ember. They communicate with each end through jsonAPI, and currently I'm using localhost for debugging purpose:

import DS from 'ember-data';

export default DS.JSONAPIAdapter.extend({
  // Connect to Rails server
  host: 'http://localhost:3000',
});

If I can make 199.116.235.154 host for my ruby on rails backend, will it also work for my ember frontend by changing localhost to 199.115.235.154?

Community
  • 1
  • 1
RandomEli
  • 1,527
  • 5
  • 30
  • 53

2 Answers2

0

Please consider using proxy. it's easily setting up on Nginx:

Just install nginx and find the configuration file for it (normally it is located in /etc/nginx/nginx.conf) and add following block:

 server {
   ...
    location / {
      proxy_pass http://127.0.0.1:3000;
    }
   ...

and then you can access your backend rails app via http://public-ip/, suppose your nginx is running on regular 80 port.

kyrre
  • 327
  • 3
  • 9
0
  1. Precompile your ember assets in rails: ember-cli-rails
  2. Deploy your app in heroku docker: Deploy rails app in heroku docker

The good thing for docker is it provide you pretty clear and accurate solution in the console when you got an error when build/run the docker machine.

RandomEli
  • 1,527
  • 5
  • 30
  • 53