diff --git a/docker-compose.yml b/docker-compose.yml index d63172b7..0bf55bdd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -204,7 +204,7 @@ services: # Web Server # ------------------------------------------------------------ httpd: - image: devilbox/${HTTPD_SERVER:-nginx-stable}:0.20 + image: devilbox/${HTTPD_SERVER:-nginx-stable}:0.21 environment: @@ -253,6 +253,7 @@ services: - PHP_FPM_ENABLE=1 - PHP_FPM_SERVER_ADDR=php - PHP_FPM_SERVER_PORT=9000 + - PHP_FPM_TIMEOUT=${HTTPD_TIMEOUT_TO_PHP_FPM:-180} ports: # ---- Format: ---- diff --git a/docs/configuration-files/env-file.rst b/docs/configuration-files/env-file.rst index 4edae035..78ef333e 100644 --- a/docs/configuration-files/env-file.rst +++ b/docs/configuration-files/env-file.rst @@ -1401,6 +1401,32 @@ changing the server name or adding locations to other assets. .. * :ref:`customize_all_virtual_hosts_globally` +.. _env_httpd_timeout_to_php_fpm: + +HTTPD_TIMEOUT_TO_PHP_FPM +^^^^^^^^^^^^^^^^^^^^^^^^ + +This variable specifies after how many seconds the webserver should quit an unanswered connection +to PHP-FPM. + +Ensure that this value is higher than PHP's ``max_execution_time``, otherwise the PHP script +could still run and the webserver will simply drop the connection before getting an answer +by PHP. + +If ``HTTPD_TIMEOUT_TO_PHP_FPM`` is smaller then ``max_execution_time`` and a script runs longer +than ``max_execution_time``, you will get a: ``504 Gateway timeout`` in the browser. + +If ``HTTPD_TIMEOUT_TO_PHP_FPM`` is greater then ``max_execution_time`` and a script runs longer +than ``max_execution_time``, you will get a proper PHP error message in the browser. + + ++------------------------------+-------------------+------------------+ +| Name | Allowed values | Default value | ++==============================+===================+==================+ +| ``HTTPD_TIMEOUT_TO_PHP_FPM`` | positive integer | ``180`` | ++------------------------------+-------------------+------------------+ + + MySQL ----- diff --git a/docs/features.rst b/docs/features.rst index b4c18f6f..a648c2db 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -54,7 +54,7 @@ separetely. Virtual host domains ^^^^^^^^^^^^^^^^^^^^ Each of your virtual host will have its own domain. TLD can be freely chosen, such as ``*.loc`` or -``*.local``. Be aware that some TLD's can cause problems. Read more here: :ref:`_env_tld_suffix`. +``*.local``. Be aware that some TLD's can cause problems. Read more here: :ref:`env_tld_suffix`. Service and version choice diff --git a/docs/support/troubleshooting.rst b/docs/support/troubleshooting.rst index 559c8d8b..e96c9098 100644 --- a/docs/support/troubleshooting.rst +++ b/docs/support/troubleshooting.rst @@ -207,10 +207,12 @@ Check your Docker settings to allow shared volumes for the path of the Devilbox This error occurs when the upstream PHP-FPM server takes longer to execute a script, than the timeout value set in the web server for PHP-FPM to answer. -For that to fix one must increase the PHP-FPM/Proxy timeout settings on the virtual host. +For that to fix one must increase the PHP-FPM/Proxy timeout settings in the ``.env`` file. +:ref:`env_httpd_timeout_to_php_fpm` .. seealso:: + * :ref:`env_httpd_timeout_to_php_fpm` * https://github.com/cytopia/devilbox/issues/280 * https://github.com/cytopia/devilbox/issues/234 diff --git a/env-example b/env-example index 898c5b83..06677397 100644 --- a/env-example +++ b/env-example @@ -478,6 +478,16 @@ HTTPD_DOCROOT_DIR=htdocs HTTPD_TEMPLATE_DIR=.devilbox +### +### Webserver timeout (in seconds) to upstream PHP-FPM server +### +### This value should be greater than PHP's max_execution_time, +### otherwise the php script could still run and the webserver will +### simply drop the connection before getting an answer by PHP. +### +HTTPD_TIMEOUT_TO_PHP_FPM=180 + + ################################################################################ ### diff --git a/templates/vhost-gen/apache22.yml b/templates/vhost-gen/apache22.yml index e7d2e5da..158de62e 100644 --- a/templates/vhost-gen/apache22.yml +++ b/templates/vhost-gen/apache22.yml @@ -120,7 +120,7 @@ features: # PHP-FPM will not be applied to a reverse proxy! php_fpm: | # PHP-FPM Definition - ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://__PHP_ADDR__:__PHP_PORT____DOCUMENT_ROOT__/$1 + ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://__PHP_ADDR__:__PHP_PORT____DOCUMENT_ROOT__/$1 timeout=__PHP_TIMEOUT__ alias: | # Alias Definition diff --git a/templates/vhost-gen/apache24.yml b/templates/vhost-gen/apache24.yml index 2b5e0ead..8703d096 100644 --- a/templates/vhost-gen/apache24.yml +++ b/templates/vhost-gen/apache24.yml @@ -131,6 +131,8 @@ features: + ProxySet timeout=__PHP_TIMEOUT__ + ProxySet connectiontimeout=__PHP_TIMEOUT__ # If the php file doesn't exist, disable the proxy handler. diff --git a/templates/vhost-gen/nginx.yml b/templates/vhost-gen/nginx.yml index c76f9210..44c4c09f 100644 --- a/templates/vhost-gen/nginx.yml +++ b/templates/vhost-gen/nginx.yml @@ -112,10 +112,14 @@ features: try_files $uri = 404; include fastcgi_params; + # https://stackoverflow.com/questions/1733306/nginx-errors-readv-and-recv-failed/51457613#51457613 + fastcgi_keep_conn off; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_pass __PHP_ADDR__:__PHP_PORT__; + fastcgi_read_timeout __PHP_TIMEOUT__; fastcgi_index index.php; fastcgi_intercept_errors on;