可以在 Windows 上部署带有 ActionCable 的 Rails 5 应用程序吗?

Can a Rails 5 application with ActionCable be deployed on Windows?

我有一个 Rails 5 应用程序,我打算在 Linux 上部署它,但是因为我们需要一些非常特定的 Windows-only 软件,所以我需要部署它Windows 服务器 2012 R2。我的软件堆栈(或组合)应该是 Nginx/Puma/Rails/PostgreSQL/Redis。 Windows 除了 Puma,所有东西都为我安装,Rails 文档说我需要 Puma for ActionCable。

如何让 Puma 在 Windows 上 运行?我已经看到并尝试了一些要尝试的片段,我也看到并尝试了一些关于不该做什么的片段,例如 运行ning 在守护进程模式下,因为不支持 fork() 。有没有人有一套可重复的说明,说明如何让 Puma 使用 Rails 应用程序在 Windows 上工作?

或者,如果 Puma 不是 Windows 的启动器,是否有可重复的替代方法来将带有 ActionCable 的 Rails 5 应用程序部署到 Windows 服务器主机(例如 Windows 2012 R2)?

根据 github 页面中的 readme file,请记住以下事项:

  • 不支持守护进程模式。所以评论out/remove下面,如果有这样的行。

    daemonize false
    
  • Workers 不在 Windows 中工作,因为它不支持进程。我们希望工人是“0”。所以注释掉以下几行:

    workers 2        # The default is "0"
    preload_app!
    
  • 服务器套接字在重新启动时不是无缝的,它们必须关闭并重新打开。这些平台无法将描述符传递给暴露给 ruby.

  • 的新进程
  • 不要使用 unix 套接字,而是将服务器绑定到 "tcp://"。所以注释掉如下所示的任何行:

    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 请求),请尝试 this answer。如果它不起作用,然后从 config/environments/production.rb 或 config/environments/production.rb 注释掉这一行(取决于你想要 运行 Puma)

    config.force_ssl = true
    

puma.rb 文件可能如下所示:

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 应该可以了。