[Heroku] WebServer を WEBrick から thin に変更する方法 – [Rails 3.x on Heroku/Cedar]
単に Heroku に Rails アプリをデプロイしただけの最初の状態では、Webサーバーは WEBrick で動いています。
$ heroku ps Process State Command ------- ------------ --------------------------------- web.1 idle for 94h bundle exec rails server -p $PORT |
Webserver
By default, your app’s web process runs rails server, which uses Webrick. This is fine for testing, but for production apps you’ll want to switch to a more robust webserver. We recommend Thin.
To use Thin with Rails 3, add it to your Gemfile:
gem 'thin'Run bundle install to set up your bundle locally.
■ Procfile の作成・追記
web: bundle exec rails server thin -p $PORT -e $RACK_ENV |
echo "RACK_ENV=development" >>.env |
.gitignore に .env を無視するように追記します。
# Ignore Heroku for local config /.env |
■ Foreman のインストール
$ gem install foreman |
■ Foreman の起動
Foreman を起動して、ブラウザから http://localhost:5000/ にアクセスして、確認します。
$ foreman start |
■ Heroku へデプロイ
$ git add -A $ git commit -m "use thin via procfile" $ git push heroku |
■ thin で起動しているか確認する
$ heroku ps Process State Command ------- ----------- ------------------------------------ web.1 idle for 4m bundle exec rails server thin -p $.. |
以上です。
【参考】
・Getting Started with Rails 3.x on Heroku/Cedar | Heroku Dev Center
・The Process Model | Heroku Dev Center
・Fiberを使ってem-http-requestとかを同期的に呼び出す – daily gimite
・Issue #13: FiberError with Rails 3.1 on Heroku · mperham/rack-fiber_pool · GitHub
・mperham/rack-fiber_pool · GitHub