ruby - 如何更改sinatra 的host?

浏览:26日期:2022-10-23

问题描述

完全不了解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 可以,求指导

问题解答

回答1:

看官方文档啊 config.ru

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

# app.rbrequire ’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来运行你的程序

相关文章: