マイ備忘録

あくまで個人の意見、メモです。

nginxのproxy timeout設定

nginxのupstreamとしてRailsをおいているが、タイムアウトが発生し始めたので改めて確認。

proxy moduleのドキュメント

nginx.org

proxy_connect_timeout

https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_connect_timeout

Defines a timeout for establishing a connection with a proxied server. It should be noted that this timeout cannot usually exceed 75 seconds.

とのこと。あくまでTCP接続確立時のタイムアウトなので、upstreamへのリクエストの送信やレスポンスの待機には影響しない。

proxy_read_timeout

https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout

Defines a timeout for reading a response from the proxied server. The timeout is set only between two successive read operations, not for the transmission of the whole response. If the proxied server does not transmit anything within this time, the connection is closed.

とのこと。upstream から設定した時間内に何もレスポンスがなかった場合にTCPのコネクションがcloseされる。

proxy_send_timeout

https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_send_timeout

Sets a timeout for transmitting a request to the proxied server. The timeout is set only between two successive write operations, not for the transmission of the whole request. If the proxied server does not receive anything within this time, the connection is closed.

とのこと。upstream にリクエストを送信するためにかかる最大時間を設定する。設定した時間内にnginxがデータを送信できなかった場合、TCPのコネクションがcloseされる。

今回の問題は、Rails経由でS3にそこそこのサイズのデータをアップロードするので、upstreamからのレスポンスが返ってこない状態になっていると予想している(proxy_read_timeoutの設定変更が必要)。