Heim  >  Fragen und Antworten  >  Hauptteil

ruby - 如何更改sinatra 的host?

完全不了解web 开发 买了个vps 想自己试试, 想用sinatra 写个web service

require 'sinatra' 
get '/'do 
"Just Do It" 
server = ::Thin::Server.new(options[:Host] || '106.3.38.47', 
options[:Port] || 996, 
app) 
end 

我想吧 sinatra 的Demo 跑在我的VPS上,应该如何做啊,106.3.38.47:996无法访问,localhost:4567 可以,求指导

天蓬老师天蓬老师2712 Tage vor613

Antworte allen(1)Ich werde antworten

  • 巴扎黑

    巴扎黑2017-04-21 11:17:26

    看官方文档啊 config.ru

    使用config.ru运行传统方式的应用 编写你的应用:

    # app.rb
    require 'sinatra'
    
    get '/' do
      'Hello world!'
    end
    

    加入相应的 config.ru:

    require './app'
    run Sinatra::Application
    

    什么时候用 config.ru? 以下情况你可能需要使用 config.ru:

    • 你要使用不同的 Rack 处理器部署 (Passenger, Unicorn, Heroku, …).

    • 你想使用一个或者多个 Sinatra::Base的子类.

    • 你只想把Sinatra当作中间件使用,而不是端点。

    你并不需要切换到config.ru仅仅因为你切换到模块化方式, 你同样不需要切换到模块化方式, 仅仅因为要运行 config.ru.

    然后,你需要使用thin或者Passenger,unicorn等web server来运行你的程序

    Antwort
    0
  • StornierenAntwort