lundi 28 mars 2016

How to binding an external host for ruby on rails?

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?




Aucun commentaire:

Enregistrer un commentaire