Apache2 Proxy timeout

94,194

Solution 1

I finally fixed this problem after testing several configuration parameters. I tested the solution twice, removing all previous changes. Only one parameter was needed for me to fix it.

For the latest versions of httpd and mod_proxy_fcgi you can simply add timeout= to the end of the ProxyPassMatch line, e.g.:

ProxyPassMatch ^/(.+\.php.*)$ fcgi://127.0.0.1:9000/<docroot>/$1 timeout=1800

For older versions it was a little more complicated, e.g.:

<Proxy fcgi://127.0.0.1:9000>
  ProxySet timeout=1800
</Proxy>
ProxyPassMatch ^/(.+\.php.*)$ fcgi://127.0.0.1:9000/<docroot>/$1

I needed to add the Proxy directive to set the timeout to 30 minutes. In some applications, usually when operating database, there are routines that can take more than 10 minutes to execute. I temporary set the timeout to 30 minutes to ensure they finish. Specifically useful when using the installation wizard, which takes too much time (in my humble opinion).

By the way the intial input that helped me to solve this issue was found in the following URL address.

Solution 2

I wanted to point out that although this answer works great for older versions, it breaks under recent versions of Apache 2.4 with error code AH00526. ProxyPass and ProxyPassMatch or <Proxy> and <ProxyMatch> cannot be used together within the same worker name. This used to function just fine, so don't know if that was changed by design or if it's a bug.

Either way, you can fix this by only using a ProxyPassMatch with parameter 'timeout=120' (or whatever your desired value is), e.g.:

ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9001/path/to/webroot/$1 timeout=120

Solution 3

I have Apache 2.4.6, but the patch to fix it is provided in Apache >= 2.4.8. The key here is to start your output immediately so that Apache (mod_proxy_fcgi) thinks the connection is active.

For example, I am using PHP and the DB query for my AJAX call takes > 30 seconds. Because I know that the overall response will be "Content-Type: application/json", I send that header immediately.

#1: Start output immediately
#Note: Sending the header is innocuous
#   it can be changed later using the $replace parameter
#   (see #3)
header( 'Content-Type: application/json' );

#2: Run slow query
mysql_query( "SELECT * FROM giant_table" );

#3: Change header as needed
header( 'Content-Type: application/csv', true );

#output content

Solution 4

I noted that you are using PHP-FPM. I too use it, but with Apache 2.4.6.

Assuming that the issue has existed for some time, it seems to be that the timeout value for mod_proxy_fcgi is hard coded. I wrote up what I found here

Solution 5

Shouldn't that be:

<IfModule mod_proxy.c>

Be sure the php.ini setting max_execution_time is set to 600 also. (check phpinfo() on the live page to make sure you're seeing the actual value used)

As Jenny said, set the php-fpm setting

request_terminate_timeout 610s

(note the s at the end)

There's not much to configure with mod_proxy_fcgi itself, as you can see on the apache page. http://httpd.apache.org/docs/current/mod/mod_proxy_fcgi.html

Turn on php-fpm debug logging also so you can see where it times out there. http://php-fpm.org/wiki/Configuration_File (also turn on catch_workers_output)

And turn on debug level logging for the mod_proxy and mod_proxy_fcgi modules since you're using apache 2.4. Very nice feature, turn on just for the modules you need: http://httpd.apache.org/docs/current/mod/core.html#loglevel

If those don't help, post your php-fpm config file.

As a last resort, maybe some daemon is killing long running process?

Share:
94,194

Related videos on Youtube

wyqydsyq
Author by

wyqydsyq

Updated on September 18, 2022

Comments

  • wyqydsyq
    wyqydsyq almost 2 years

    I have Apache2 with PHP + PHP-FPM configured according to:

    http://wiki.apache.org/httpd/PHP-FPM

    I am writing a script that will take a long time to execute on an internal Vhost, but keep getting timed out, everything runs flawlessly if the script executes in under 30 seconds.

    My apache log tells me:

    [Wed Apr 17 21:57:23.075175 2013] [proxy_fcgi:error] [pid 9263:tid 140530454267648] (70007)The timeout specified has expired: [client 58.169.202.172:49017] AH01075: Error dispatching request to :, referer:
    

    When trying to run the script I am given a 503 Service Unavailable after exactly 30 seconds of execution time. Logically this would mean I have a timeout directive or setting set to 30 seconds, but I have these in my Vhost's config:

    Timeout 600
    <IfModule proxy_module>
        ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9001/home/pyrokinetiq/scripts/$1 timeout=600
        ProxyTimeout 600
    </IfModule>
    

    (php-fpm is running on port 9001 for me)

    I have also tried placing the Timeout and ProxyTimeout in httpd.conf with no difference.

    It seems there's another timeout setting somewhere that's specific to mod_proxy_fcgi, but I can't find it. I installed the Apache2 httpd from the official tarball, none of the mods seem to have come with any configuration files.

    If anyone can point me in the right direction it would be much appreciated.

  • wyqydsyq
    wyqydsyq about 11 years
    I've set the request_terminate_timeout to 400, still no change :( I have a feeling that there's something I need to set for mod_proxy_fcgi, but it didn't seem to come with any configuration files.
  • Stewart Adam
    Stewart Adam over 9 years
    It looks like this broke under recent versions of Apache, AH00526: ProxyPass/<Proxy> and ProxyPassMatch/<ProxyMatch> can't be used altogether with the same worker name
  • Stewart Adam
    Stewart Adam over 9 years
    I have resolved the above by adding a parameter 'timeout=120' at the end of the ProxyPassMatch line.
  • Stewart Adam
    Stewart Adam about 9 years
    @Palantir glad to hear it! Submitted as answer.
  • Professor Falken
    Professor Falken about 6 years
    Two more things I needed: First, you -must- set "Timeout" and "ProxyTimeout" in your global apache config file to be longer than the other FPM timeouts. Second, My FPM pool was listening on a unix socket and I use SetHandler like so: [ SetHandler "proxy:unix:/var/run/php/example.com-php7.0-fpm.sock|fcgi://‌​localhost:8000" ] . But <Proxy> matches on the fcgi://localhost part of the SetHandler line (the part AFTER the |... which isn't even actually used !) and NOT the unix:/var/run/ part. so to config timeouts for above use: <Proxy fcgi://localhost:8000> and not <Proxy unix:/var/run/...
  • 4wk_
    4wk_ about 3 years
    As of today (2021), the content at the "URL address" is gone. Please read it on web.archive.org/web/20200730023817/http://… (I cannot suggest it as edit because "suggested edit queue is full")