Ruby Sinatra Webservice 在 localhost:4567 上运行,但不在 IP 上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16832472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ruby Sinatra Webservice running on localhost:4567 but not on IP
提问by foobar
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:4567but when I replace localhost with the local ip of my machine say, 192.168.103.99:4567it 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.
我在 Windows 7 32 位操作系统上有一个 ruby(使用 sinatra)网络服务。它在端口4567上运行。当我使用localhost:4567时它工作正常,但是当我用我机器的本地 ip 替换 localhost 时说,192.168.103.99 :4567它不起作用,并且无法连接。我已经禁用了防火墙,绕过代理并将端口 4567 添加到异常中,仍然没有运气。
What might be the issue ?
可能是什么问题?
回答by foobar
From the comment of @SudarshanShubakar following worked for me.
来自@SudarshanShubakar 的评论对我有用。
ruby app.rb -o 0.0.0.0
ruby app.rb -o 0.0.0.0
回答by chikamichi
When using the built-in server through the run! if app_file == $0check, Sinatra's docexplains that set :bind, '0.0.0.0'is required to make the interface available outside the localhostlayer.
当通过run! if app_file == $0检查使用内置服务器时,Sinatra 的文档解释说set :bind, '0.0.0.0'需要使接口在localhost层外可用。
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.
不需要使用自定义 IP 地址或反向 DNS (mydomain.com...):'0.0.0.0'是Sinatra 预期的合法值,它将被正确解释。
Therefore, a minimal, self-contained Sinatra application made available on all interfaces, not only localhost, would be:
因此,一个最小的、自包含的 Sinatra 应用程序可用于所有接口,不仅仅是localhost,将是:
require 'sinatra/base'
class MyApp < Sinatra::Base
set :bind, '0.0.0.0'
get '/' do
'Hello World'
end
run! if app_file == set :bind, '192.168.103.99'
end
回答by unused
To set server hostname or IP-address use sinatra settingbindlike
要设置服务器主机名或 IP 地址,请使用sinatra 设置绑定,例如
require 'rubygems'
require 'sinatra'
require "dbi"
set :bind, '192.168.200.185'
get '/' do
'hello word'
end
回答by Erick Guardado
this
这个
##代码##
