Running Nginx with Concrete5

I’ve been sitting here all day bashing my head against one simple problem - getting Concrete5 working behind Nginx.

Concrete5 is a beautiful, simple php-based CMS - a loud answer to the complexity of Joomla and Drupal, but of course missing some of the power too. It’s perfect for web sites that aren’t managed by total geeks.

Nginx is the world’s fastest and most efficient web server. Hands down, no competition, no argument.

The problem I had integrating the two stems from nginx+php-fastcgi not correctly passing through the PATH_INFO variable so you can have URLs like “http://example.com/index.php/path/to/file”.

The solution was to slightly alter the usual php-fastcgi parameter processing. Below is my complete config for my concrete5 site. This worked on Debian Lenny with nginx 0.7.59.

 


server {
        listen          80;
        server_name     www.example.com;
        autoindex on;

	location / {
	       root /var/www/example.com/concrete5/;
                index index.php;

		if (!-f $request_filename){
                   set $rule_0 1$rule_0;
               }
               if (!-d $request_filename){
                    set $rule_0 2$rule_0;
               }
               if ($rule_0 = "21"){
                    rewrite ^/(.*)$ /index.php/$1 last;
               }
	}

        location ~ \.php($|/) {
           set  $script     $uri;
            set  $path_info  "";

            if ($uri ~ "^(.+\.php)(/.+)") {
              set  $script     $1;
              set  $path_info  $2;
            }
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME  /var/www/example.com/concrete5$fastcgi_script_name;
	  fastcgi_param URI $uri;
	  fastcgi_param PATH_INFO $path_info;
          include        /etc/nginx/fastcgi.conf;
        }
}