Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache + PHP-FPM Set proxy timeout only to specific path

I have Apache 2.4 with PHP 5.5 without using php_mod but with PHP-FPM and mod_proxy_fcgi, so I added the following to the vhost:

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:7000/home/var/www/site/$1

This worked well but when I had some problems with timeouts I added the following code in order to fix this issue to the vhost file:

<Proxy fcgi://127.0.0.1:7000>
    ProxySet timeout=3600
</Proxy>
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:7000/home/var/www/site/$1

However, I would like to add this timeout only to the administration panel of the website, which is www.site.com/admin/xxx. I tried to add the location tag like below, but it didn't worked (Apache fails when restarting).

<LocationMatch ^/admin/.*\.php(/.*)?$>
    <Proxy fcgi://127.0.0.1:7000>
        ProxySet timeout=3600
    </Proxy>
</LocationMatch >
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:7000/home/var/www/site/$1

First of all, is that possible? Then which would be the correct syntax?

Many thanks for your time

like image 654
MatthewK Avatar asked Jan 20 '15 11:01

MatthewK


1 Answers

Just use the Proxy wildcard with /admin/*

While this will allow ANY script beneath admin to run with the settings defined, behind an admin (and I assume login) wall, it shouldn't be an issue.

<Proxy "fcgi://127.0.0.1:7000/home/var/www/site/admin/*">
    ProxySet timeout=3600
</Proxy>

Use ProxySet outside of a Proxy directive

ProxySet within a Proxy directive can be used without defining the url/balancer/worker. But, you should still be able to use ProxySet within a Location directive.

<LocationMatch ^/admin/.*\.php(/.*)?$>
    ProxySet "fcgi://127.0.0.1:7000" timeout=3600
</LocationMatch>

If apache is still failing on startup, check the apache logs, or run strace -Ff apachectl start to find the problem, it may just be a bug in that version of apache.

However, I strongly suspect your LocationMatch regex ^/admin/.*\.php(/.*)?$ to be the cause of the apache failure.

like image 103
Tony Chiboucas Avatar answered Sep 30 '22 10:09

Tony Chiboucas