Apache:使用mod FastCGI的Alias指令

该服务器被configuration为处理与fastcgi的PHP文件:

<IfModule mod_fastcgi.c> AddHandler application/x-httpd-php .php Action application/x-httpd-php /fcgi-bin/php-fpm virtual ScriptAlias /fcgi-bin/php-fpm /fcgi-extsrvs-phpfpm <Location "/fcgi-bin/php-fpm"> Order Deny,Allow Deny from All Allow from env=REDIRECT_STATUS </Location> </IfModule> 

然后定义一个虚拟主机来使用这个fastcgi:

 <VirtualHost *:80> ServerName mydomain.org DocumentRoot /var/www/mydomain.org <Location /> Order Allow,Deny Allow from All AllowOverride None </Location> <IfModule mod_fastcgi.c> # use the socket as defined for this pool FastCgiExternalServer /fcgi-extsrvs-phpfpm -socket /var/run/php5-fpm/mydomain.org.sock </IfModule> # problem here AliasMatch ^/(.*) /var/www/mydomain.org/index.php </VirtualHost> 

一切工作正常,直到我添加AliasMatch行(与别名相同的问题)。 目标是通过index.php脚本处理每个请求。 这会导致与以下日志500错误:

 [error] [client 88.xxx.xxx.20] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. [debug] core.c(3112): [client 88.xxx.xxx.20] r->uri = /fcgi-bin/php-fpm/fcgi-bin/php-fpm/fcgi-bin/php-fpm/fcgi-bin/php-fpm/fcgi-bin/php-fpm/fcgi-bin/php-fpm/fcgi-bin/php-fpm/fcgi-bin/php-fpm/fcgi-bin/php-fpm/fcgi-bin/php-fpm/ [debug] core.c(3118): [client 88.xxx.xxx.20] redirected from r->uri = /fcgi-bin/php-fpm/fcgi-bin/php-fpm/fcgi-bin/php-fpm/fcgi-bin/php-fpm/fcgi-bin/php-fpm/fcgi-bin/php-fpm/fcgi-bin/php-fpm/fcgi-bin/php-fpm/fcgi-bin/php-fpm/ ... [debug] core.c(3118): [client 88.xxx.xxx.20] redirected from r->uri = /fcgi-bin/php-fpm/ [debug] core.c(3118): [client 88.xxx.xxx.20] redirected from r->uri = / 

我的猜测是ScriptAlias和AliasMatch之间有冲突,但我不知道如何解决它。

她是一个simmilar问题的解决schemehttp://www.tokiwinter.com/avoiding-infinite-recursion-with-mod_rewrite-and-mod_fastcgi/ TL; DR使用mod_rewrite和禁用重写的PHP脚本url

但我强烈build议移动到apache2.4和使用mod_proxy_fcgi https://httpd.apache.org/docs/2.4/mod/mod_proxy_fcgi.html你可以在哪&#x91CC;

 <FilesMatch "\.php$"> SetHandler "proxy:unix:/var/run/php5-fpm/mydomain.org.sock|fcgi://host1/" </FilesMatch> 

而所有的redirect,重写应该按预期工作。 顺便说一句mod_fastcgi已经过时了,丑陋。 如果你喜欢留在2.2(现在是EOL)你可以尝试https://github.com/lazy404/mod_fastcgi_handler (我用它在一个繁忙的网站与PHP-FPM没有任何问题)它的configuration也是干净的并与redirect兼容。