如何使用’rails s puma’运行配置文件的rails puma服务器

我可以使用rails s puma或只是puma在rails中运行puma服务器。

根据这个答案 ,运行rails s puma使服务器知道rails环境。 它显示了单独运行puma服务器错误等。

我想像这样设置一个配置文件:

配置/ puma.rb

 workers Integer(ENV['PUMA_WORKERS'] || 3) threads Integer(ENV['MIN_THREADS'] || 1), Integer(ENV['MAX_THREADS'] || 16) rackup DefaultRackup port ENV['PORT'] || 3000 environment ENV['RACK_ENV'] || 'development' ... 

如果我运行puma -C config/puma.rb一切正常。 但是,如果我运行rails s pumarails s puma如何给puma选项。 我尝试过以下方法:

 rails s puma # Puma server works but no config file is passed in. rails s puma -C config/puma.rb # Invalid option -C rails s puma -c config/puma.rb # Undefined method 'workers'. So rails is # trying to use the config instead of puma? 

我也尝试按照puma文档将配置文件放在config/puma/development.rb中。

感谢任何帮助:)

使用rails s puma加载你的puma配置文件是不可能的,如https://github.com/puma/puma/issues/512所示 ,你可能想在这里看一个类似的问题我该怎么办?让’puma’自动启动,当我运行`rails server`(就像Thin一样)时会讨论这个问题

我发现使用Foreman( https://github.com/ddollar/foreman )是一个很好的解决方法,并提供额外的灵活性。

Heroku为此编写了一个很好的指南( https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server )。 下面是一个非常快速的入门。

第1步 :安装Foreman。 下面是Mac OS X的示例,Foreman站点上的完整指南

 $ brew install foreman 

第2步 :将其添加到您的Gemfile:

 gem 'puma' 

第3步 :创建一个名为Procfile的文件:

 web: bundle exec puma -C config/puma.rb 

第4步 :现在使用启动您的应用程序

 $ foreman start 00:36:05 web.1 | started with pid 19869 00:36:05 web.1 | [19869] Puma starting in cluster mode... 00:36:05 web.1 | [19869] * Version 2.11.1 (ruby 2.2.1-p85), codename: Intrepid Squirrel 00:36:05 web.1 | [19869] * Min threads: 1, max threads: 1 00:36:05 web.1 | [19869] * Environment: development 00:36:05 web.1 | [19869] * Process workers: 1 00:36:05 web.1 | [19869] * Preloading application 00:36:07 web.1 | [19869] * Listening on tcp://0.0.0.0:3000 00:36:07 web.1 | [19869] Use Ctrl-C to stop 00:36:07 web.1 | [19869] - Worker 0 (pid: 19870) booted, phase: 0 

不幸的是你不能。 今天我必须让Puma在我的开发环境中使用ssl,所以我在rails应用程序(Rails 5)中编辑了文件config / puma.rb并添加了:

 ssl_bind '127.0.0.1', '3000', { key: 'path_to_you_key_file', #/Users/DevRuby/.ssh/server.key cert: 'path_to_yout_cert_file', #/Users/DevRuby/.ssh/server.crt verify_mode: 'none' #fix errors due to self-signed certificate } 

并添加到我的config / environments / development.rb以下行以启用日志发送到STDOUT:

 config.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) 

而不是使用#rails s启动我的应用程序,我现在使用命令#puma加载config / puma.rb配置文件中的所有设置。