LoginSignup
46
41

More than 5 years have passed since last update.

nginx+Rails+unicorn 環境下で タイムアウト値を設定

Last updated at Posted at 2015-02-10

nginx + Rails + unicorn の環境で、レスポンスタイムが最大 120 秒の外部 API を実行した際、
Rails ( nginx ) からはタイムアウト ( 60秒 ) が返ってきているにもかかわらず、
実行された外部 API 側では処理されてしまうという現象が発生したので、タイムアウト値を設定した。

unicorn 側は、外部 API の 120 秒から余裕を持って 150 と設定

config/unicorn.rb
worker_processes 4
timeout 150
root = File.expand_path(File.dirname(__FILE__) + '/../')

listen      '/tmp/hoge.sock'
pid         '/tmp/hoge.pid'
stderr_path "#{root}/log/unicorn_error.log"
stdout_path "#{root}/log/unicorn.log"

nginx.conf については、unicorn のタイムアウトから更に余裕を持って 160 とし、
下記ディレクティブを追加

proxy_read_timeout    160;

これで、アクセスすると、150 秒経つと、unicorn のタイムアウトが発生し、
502 Bad Gateway が返ってくる

ちなみに、nginx 側のタイムアウトの場合は、504 Gateway Time-out が返ってくる

後、外部 API 実行する処理の部分にも、TIME_OUT の処理も必要ですね。

46
41
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
46
41