Whilst converting tokiwinter.com away from mod_php to mod_fastcgi/PHP-FPM, I experienced the following error:
|
1 |
[Thu Jul 11 14:29:31 2013] [error] [client 192.168.122.1] 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. |
Enabling LogLevel debug for the VirtualHost showed the following extra detail:
|
1 2 3 4 5 6 |
[Thu Jul 11 14:29:31 2013] [debug] core.c(3072): [client 192.168.122.1] r->uri = /index.php [Thu Jul 11 14:29:31 2013] [debug] core.c(3078): [client 192.168.122.1] redirected from r->uri = /cgi-bin/php5.fcgi/index.php [Thu Jul 11 14:29:31 2013] [debug] core.c(3078): [client 192.168.122.1] redirected from r->uri = /index.php [Thu Jul 11 14:29:31 2013] [debug] core.c(3078): [client 192.168.122.1] redirected from r->uri = /cgi-bin/php5.fcgi/index.php [Thu Jul 11 14:29:31 2013] [debug] core.c(3078): [client 192.168.122.1] redirected from r->uri = /index.php ... |
We can see that the rewrites required for WordPress in .htaccess are interfering with the correct operation of mod_fastcgi. The net result - HTTP 500 Internal Server Error for all our clients.
The fix is easy enough - add the following additional rewrite to .htaccess for the WordPress installation:
|
1 2 |
RewriteCond %{REQUEST_URI} ^/cgi-bin/php5.fcgi(.*) RewriteRule . - [L] |
i.e. if the request URI is a mod_fastcgi request, do not apply any rewrites. My complete .htaccess file in my WordPress VirtualHost is now:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_URI} ^/cgi-bin/php5.fcgi(.*) RewriteRule . - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress |
This works for me with the following VirtualHost configuration:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin toki@tokiwinter.com ServerName tokiwinter.com ServerAlias www.tokiwinter.com DocumentRoot /var/www/virtualhosts/tokiwinter.com/htdocs ScriptAlias "/cgi-bin/" "/var/www/virtualhosts/tokiwinter.com/htdocs/cgi-bin/" FastCGIExternalServer /var/www/virtualhosts/tokiwinter.com/htdocs/cgi-bin/php5.fcgi -host 127.0.0.1:9000 ErrorLog logs/tokiwinter.com-error_log CustomLog logs/tokiwinter.com-access_log common <Directory /> AllowOverride all Order allow,deny Allow from all AddType application/x-httpd-fastphp5 .php Action application/x-httpd-fastphp5 /cgi-bin/php5.fcgi </Directory> DirectoryIndex index.php </VirtualHost> |
Your mileage may well vary.