可以在 Windows 上部署带有 ActionCable 的 Rails 5 应用程序吗? [英] Can a Rails 5 application with ActionCable be deployed on Windows?
问题描述
我有一个 Rails 5 应用程序,我计划在 Linux 上部署它,但是因为我们需要一些非常特定的 Windows 专用软件的访问权限,所以我需要将它部署在 Windows Server 2012 R2 上.我的软件堆栈(或混合)应该是 Nginx/Puma/Rails/PostgreSQL/Redis.除了 Puma 之外,Windows 上的所有东西都为我安装,Rails 文档说我需要 Puma 来安装 ActionCable.
I have a Rails 5 application which I was planning to deploy on Linux, but because we needed some access very specific Windows-only software, I need to deploy it on Windows Server 2012 R2. My software stack (or mix) was supposed to be Nginx/Puma/Rails/PostgreSQL/Redis. Everything installs for me on Windows except Puma, and the Rails documentation says that I need Puma for ActionCable.
如何让 Puma 在 Windows 上运行?我看过并尝试过一些尝试的片段,我也看过并尝试过一些不该做的事情的片段,例如在守护进程模式下运行,因为不支持 fork().有没有人有一套可重复的说明,说明如何让 Puma 使用 Rails 应用程序在 Windows 上工作?
How do I get Puma to run on Windows? I have seen and tried snippets of things to try, and I have also seen and tried snippets on what not to do, such as running in daemon mode because fork() is not supported. Does anybody have a repeatable set of instructions on how to get Puma to work on Windows with a Rails application?
或者,如果 Puma 不是 Windows 入门者,是否有可重复的替代方法来将带有 ActionCable 的 Rails 5 应用程序部署到 Windows Server 主机(例如 Windows 2012 R2)?
Or, if Puma a non-starter for Windows, is there a repeatable alternative for deploying a Rails 5 application with ActionCable to a Windows Server host (e.g. Windows 2012 R2)?
推荐答案
根据 来自 github 页面的自述文件,请记住以下几点:
According to the readme file from the github page, following things to keep in mind:
不支持守护进程模式.所以注释掉/删除以下内容,如果有这样的行.
daemon mode is not supported. so comment out/remove the following, if there is such line.
daemonize false
Workers 不能在 Windows 中工作,因为它不支持进程.我们希望工人为0".所以注释掉以下几行:
Workers do not work in Windows since it does not support processes. We want the workers to be "0". So comment out following lines:
workers 2 # The default is "0"
preload_app!
服务器套接字在重新启动时不是无缝的,它们必须关闭并重新打开.这些平台无法将描述符传递给暴露给 ruby 的新进程.
server sockets are not seamless on restart, they must be closed and reopened. These platforms have no way to pass descriptors into a new process that is exposed to ruby.
不要使用unix socket,而是将服务器绑定到tcp://".因此,注释掉如下所示的任何行:
Do not use unix socket, instead bind the server to "tcp://". So comment out any line that looks like following:
bind 'unix:///var/run/puma.sock'
bind 'unix:///var/run/puma.sock?umask=0111'
改为使用以下内容:
bind "tcp://127.0.0.1:4001"
# You don't have to if you don't need to specify a port
# since the default is "tcp://0.0.0.0:9292"
如果您在启动 Rails 服务器后看到任何 http 解析错误(格式错误的 http 请求),请尝试这个答案.如果它不起作用,则从 config/environments/production.rb 或 config/environments/production.rb 注释掉这一行(取决于您要运行 Puma 的环境)
If you see any http parse error (malformed http request) after starting rails server, try this answer. If it doesn't work, then comment out this line from config/environments/production.rb or config/environments/production.rb (depending on which environment you want to run Puma)
config.force_ssl = true
puma.rb 文件可能如下所示:
Here is what the puma.rb file might look like:
worker 0 # Not necessary. The default is "0"
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads threads_count, threads_count
bind "tcp://127.0.0.1:4001" # Not necessary. Default is "tcp://0.0.0.0:9292"
environment ENV.fetch("RAILS_ENV") { "development" }
plugin :tmp_restart
最后运行 bundle exec puma -C config\puma.rb
就可以了.
Finally run bundle exec puma -C config\puma.rb
and it should work.
这篇关于可以在 Windows 上部署带有 ActionCable 的 Rails 5 应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!