我在我的application.yml中将端口设置为3000(figaro管理env变量)
rails s
使用端口3000
但是当我运行foreman start
(按照Heroku的推荐)时,我得到以下输出
14:53:23 web.1 | started with pid 24425
14:53:23 web.1 | [24425] Puma starting in cluster mode...
14:53:23 web.1 | [24425] * Version 2.11.1 (ruby 2.2.0-p0), codename: Intrepid Squirrel
14:53:23 web.1 | [24425] * Min threads: 5, max threads: 5
14:53:23 web.1 | [24425] * Environment: development
14:53:23 web.1 | [24425] * Process workers: 2
14:53:23 web.1 | [24425] * Preloading application
14:53:24 web.1 | WARNING: Skipping key "PORT". Already set in ENV.
14:53:25 web.1 | [24425] * Listening on tcp://0.0.0.0:5000
14:53:25 web.1 | [24425] Use Ctrl-C to stop
14:53:25 web.1 | [24425] - Worker 0 (pid: 24426) booted, phase: 0
14:53:25 web.1 | [24425] - Worker 1 (pid: 24427) booted, phase: 0
Procfile
web: bundle exec puma -C config/puma.rb
配置/ puma.rb
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
ActiveRecord::Base.establish_connection
end
配置/ application.yml
PORT: "3000"
答案 0 :(得分:2)
使用.foreman文件:
port: 3000
或.env文件:
PORT=3000
任何一个应该可以工作,然后你可以使用foreman start
答案 1 :(得分:2)
port ENV['PORT'] || 3000
此行表示您将首先尝试使用ENV['PORT']
,如果不存在,您将回退到使用3000
作为端口号。那么你在PORT
开始之前的任何地方定义foreman
环境变量吗?只有在rails服务器启动后才会加载config/application.yml
个环境变量,所以在这里定义端口号是没有用的。
您可以尝试添加
位于项目目录根目录的PORT=3000
文件中的 .env
。
来源:https://devcenter.heroku.com/articles/getting-started-with-rails5#procfile