无法通过浏览器访问 RUBY 文件,但可以从命令行访问它

Cannot access a RUBY file via browser but can access it from command line

我创建了一个名为 server.rb

的文件
require 'bundler' ; Bundler.require
get '/hello-world' do
  "Hello World!"
end

当我从命令行以 curl http://localhost:4567 访问它时,我可以很容易地看到 Hello World! 但是当我通过浏览器以 http://172.16.16.14:4567

访问时

172.16.16.14是本地服务器的ip,当我点击http://172.16.16.14/时,我可以看到nginx的默认页面。

我明白了

This site can’t be reached
172.16.16.14 refused to connect. 

正如@miknik 在评论中提到的,这很可能与服务器 bind 选项有关。

在 Sintara 网站上记录:http://sinatrarb.com/configuration.html#bind---server-hostname-or-ip-address

这将允许来自任何主机的连接:

set :bind, '0.0.0.0'

Here's the actual PR for making the default bind address localhost rather than 0.0.0.0 which will allow connections from any host. https://github.com/sinatra/sinatra/pull/634