Home  >  Q&A  >  body text

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 可以,求指导

天蓬老师天蓬老师2713 days ago617

reply all(1)I'll reply

  • 巴扎黑

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

    See the official document config.ru

    Use config.ru to run traditional applications Write your app:

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

    Add the corresponding config.ru:

    require './app'
    run Sinatra::Application
    

    When to use config.ru? You may need to use config.ru:

    • You need to use different Rack processor deployment (Passenger, Unicorn, Heroku, …).

    • You want to use one or more subclasses of Sinatra::Base.

    • You only want to use Sinatra as a middleware, not an endpoint.

    You don’t need to switch to config.ru just because you switch to modular mode, and you don’t need to switch to modular mode just to run config.ru.

    Then, you need to use thin或者Passenger,unicornetc. web server to run your program

    reply
    0
  • Cancelreply