简体   繁体   English

如何初始化机架服务器监听套接字

[英]How to init rack server listening to a socket

I have to patch some code, but can't figure out exactly how. 我必须修补一些代码,但无法弄清楚具体如何。 So basically, I have a rack server which binds to a hostname and port. 所以基本上,我有一个机架服务器绑定到主机名和端口。 I woud like it to bind to a unix socket. 我喜欢它绑定到unix socket。 Problem is, I can't figure out the exact option i have to give. 问题是,我无法弄清楚我必须给出的确切选项。

Rack::Server.new(:app => @app, :port => 3000).start 

does what is expected. 做了什么预期。 I thought it would be something like this: 我以为会是这样的:

Rack::Server.new(:app => @app, :socket => "path/to/file").start

but this binds to the default port nevertheless. 但是这会绑定到默认端口。 How can I do this? 我怎样才能做到这一点?

I have found that if you pass a filename to the :Host option it binds to the unix socket and not a tcp socket. 我发现,如果您将文件名传递给:Host选项,它会绑定到unix套接字而不是tcp套接字。

The file name needs to look like this though: 但文件名必须如下所示:

/var/www/myapp/my_app.socket or ./my_app.socket /var/www/myapp/my_app.socket./my_app.socket

This will not work if it looks like a domain name like this: 如果它看起来像这样的域名,这将无效:

my_app.socket

For example here is a rackup command that works in Rack 1.2: 例如,这是一个在Rack 1.2中运行的rackup命令:

rackup -s thin -E production -o ./my_app.socket faye.ru

Or this is how you do it from ruby: 或者这是你如何从ruby做到的:

require 'rack'
require 'thin'
Rack::Handler.get('thin').run(app, :Host => './my_app.socket')

# or this works also

require 'rack'
require 'thin'
Rack::Server.new(:app => app, :Host => './my_app.socket').start

NOTE: The uppercase H in :Host this is required. 注意:大写H in :Host这是必需的。

I hope that helps! 我希望有所帮助!

Apparently this is not possible. 显然这是不可能的。 Rack-compatible servers usually support this feature, but Rack::Server "interface" does not make use of it (at least the latest version as of October 2013). 机架兼容的服务器通常支持此功能,但Rack :: Server“接口”没有使用它(至少是截至2013年10月的最新版本)。 Why not, is beyond me. 为什么不,超出我的范围。

Did you try :Socket or :File? 你试过:套接字还是:文件? Note that with Rack the options for the actual web server (webrick, thin, etc.) usually start with an uppercase character. 请注意,对于Rack,实际Web服务器(webrick,thin等)的选项通常以大写字符开头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM