我想将RoR + React SPA作为一个项目部署到heroku。作为典型的生产环境,请使用Nginx作为Web服务器,使用用户Puma作为应用程序服务器。
我试图遵循readme
的https://github.com/heroku/heroku-buildpack-nginx。
但是部署后,heroku会弹出一个错误
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
下面是我的配置
heroku buildpacks
heroku/nodejs # index 1
heroku/ruby # index 2
https://github.com/heroku/heroku-buildpack-nginx.git # index 3
Procfile
release: bundle exec rails db:migrate
web: bin/start-nginx bundle exec puma -C config/puma.rb
config / puma.rb
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count
environment ENV.fetch("RAILS_ENV") { "development" }
plugin :tmp_restart
bind ENV.fetch('PUMA_SOCK') { 'unix:///tmp/nginx.socket' }
on_worker_fork do
FileUtils.touch('/tmp/app-initialized')
end
config / nignx.conf.erb =>我删除了此文件的不重要配置,因为它太长了
http {
upstream app_server {
server unix:/tmp/nginx.socket fail_timeout=0;
}
server {
listen <%= ENV["PORT"] %>;
server_name _;
keepalive_timeout 5;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
}