LoginSignup
20
17

More than 3 years have passed since last update.

apache + php-fpm な環境での504 Gateway Timeout Errorの対応

Posted at

はじめに

CentOS8でphp-fpmがデフォルトとなりデーモンとして動きます。

先日、構築したサーバでアプリケーションのテストをしていると、504 Gateway Timeout Errorが発生したため、一部設定変更した際の備忘録です。

環境

CentOS8
apache2.4系
php7.2系

apache

apacheのタイムアウトはデフォルトで60秒なので、ここを180秒に変更。
httpd.confに追記します。

httpd.conf
Timeout 180

php

PHPでもスクリプトがパーサに強制終了される時間の設定箇所があり、デフォルトでは30秒となっているのでここを180秒に変更。

php.ini
max_execution_time = 180

その他、単一のリクエストを処理する際のタイムアウト値も設定できるので、ここも180にした。
デフォルト値は0

/etc/php-fpm.d/www.conf
request_terminate_timeout 180

反映

apache、php-fpmともにリロードして設定値を反映させよう。

# systemctl reload httpd.service
# systemctl reload php-fpm.service

その他

バックエンドのDBにMySQLやPostgreSQLを利用している場合は、そいつらのタイムアウト時間も確認する。

my.cnf
wait_timeout = 180

※デフォルトでは8時間なので大丈夫であろう。
https://dev.mysql.com/doc/refman/5.6/ja/server-system-variables.html#sysvar_wait_timeout

postgresql.conf
statement_timeout 180

※こちらもデフォルトは0なので大丈夫であろう。
https://www.postgresql.jp/document/10/html/runtime-config-client.html

20
17
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
20
17