I want to deploy RoR + React SPA to heroku as one project. As a typical production environment, use Nginx as web server and user Puma as app server.
I tried to follow readme
of https://github.com/heroku/heroku-buildpack-nginx.
But after deployment, heroku popup an error
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Below are my configs
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 => I removed unimportant config for this file because it is too long
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;
}
}
}