如何使用机架映射在不同端口上运行两个瘦(或其他)服务器? [英] How to use Rack map to run two Thin (or other) servers on different ports?

查看:38
本文介绍了如何使用机架映射在不同端口上运行两个瘦(或其他)服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是通过 Rack 对 HTTP 和 HTTPS/SSL 进行一些自动化测试,而不需要求助于代理服务器设置或类似的东西.我有一个 gem 想要测试,我希望其他人也能够运行测试,所以我希望它尽可能独立.

My aim is to do some automated testing over HTTP and HTTPS/SSL, via Rack, without recourse to a proxy server setup or anything like that. I have a gem that I want to test and I'd like for others to be able to run tests on too, so I'd like it to be as self contained as possible.

App 的代码在自己运行时运行良好,所以这里不包含它,问题出在 Rack 部分.

我想做这样的事情:

app = Rack::Builder.app do
  map "/" do
    Rack::Handler::WEBrick.run App, Port: 3000
  end

  map "/ssl" do
    Rack::Handler::WEBrick.run App, Port: 3001 # more options for SSL here...
  end
end

run app

我已经尝试了上面代码的几种组合,例如:

I've tried several combinations of the code above, like:

http = Rack::Builder.app do
  map "/" do
    run App
  end
end


https = Rack::Builder.app do  
  map "/ssl" do
    run App
  end
end

Rack::Handler::WEBrick.run http, Port: 3000
Rack::Handler::WEBrick.run https, Port: 3001 # more options for SSL here...

设置两台服务器后,我倾向于让一台服务器在列出的第一个端口上运行,然后在中断时它将在列出的下一个端口上运行第二台服务器 - 然后,在下一次中断时,9292 上的另一台服务器否则它会关闭.

With the two server setup up I tend to get one server run on the first port listed, then on interrupt it will run the second server on the next port listed - and then, on the next interrupt, either another server on 9292 or it shuts down.

我显然在做一些不太正确的事情.

I'm obviously doing something not quite right.

这很接近,但最终通过两个不同的命令行命令运行两个服务器:在不同端口上启动瘦服务器

This is quite close, but ends up running the two servers via two different command line commands: Starting thin server on different ports

非常感谢任何帮助.

推荐答案

Current Thin 不支持这个 -- 我查看了源代码.

Current Thin does not support this -- I checked the source code.

Thin v2 仍然是预发布版本,但配置代码看起来像是通过在配置文件中声明多个侦听器来支持这一点.

Thin v2 is still pre-release, but the config code looks like it supports this via declaring multiple listeners in the config file.

但 Thin v2 仍然是 alpha 版软件.

But Thin v2 is still alpha software.

您还可以切换到另一台服务器,例如 Unicorn,确实明确支持绑定到多个端口或地址.

You can also switch to another server like Unicorn that does explicitly support binding to multiple ports or addresses.

这篇关于如何使用机架映射在不同端口上运行两个瘦(或其他)服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆