Ruby Sinatra Webservice running on localhost:4567 but not on IP

人盡茶涼 提交于 2019-11-27 11:09:12

问题


I have a ruby(using sinatra) webservice on windows 7 32 bit OS. Its running on port 4567. Its working fine when I use localhost:4567 but when I replace localhost with the local ip of my machine say, 192.168.103.99:4567 it doesn't work, and fails to connect. I have already disabled the firewall, by-pass proxy and added port 4567 to exception, still no luck.

What might be the issue ?


回答1:


From the comment of @SudarshanShubakar following worked for me.

ruby app.rb -o 0.0.0.0




回答2:


When using the built-in server through the run! if app_file == $0 check, Sinatra's doc explains that set :bind, '0.0.0.0' is required to make the interface available outside the localhost layer.

It is not required to use a custom IP address or a reverse DNS (mydomain.com…): '0.0.0.0' is the legit value expected by Sinatra, which will be interpreted correctly.

Therefore, a minimal, self-contained Sinatra application made available on all interfaces, not only localhost, would be:

require 'sinatra/base'

class MyApp < Sinatra::Base
  set :bind, '0.0.0.0'

  get '/' do
    'Hello World'
  end

  run! if app_file == $0
end



回答3:


To set server hostname or IP-address use sinatra setting bind like

set :bind, '192.168.103.99'



回答4:


this

require 'rubygems'
require 'sinatra'
require "dbi"

set :bind, '192.168.200.185'
get '/' do
    'hello word'
end


来源:https://stackoverflow.com/questions/16832472/ruby-sinatra-webservice-running-on-localhost4567-but-not-on-ip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!