Nginx hosting with path appended to index.php

ironkeith asked:

I’m hosting an instance on Concrete5, and in addition to using a dynamic paths, they also use URLs in the weird form of www.mysite.com/index.php/path/to/page.

I have it mostly working, but I’m having issues getting Nginx to serve requests to www.mysite.com/, as it’s listing the directory instead of displaying index.php.

  • www.mysite.com/ -> lists the public directory, but should display index.php
  • www.mysite.com/index.php/path/to/page -> works!
  • www.mysite.com/some/other/path -> works!

Here’s my Nginx conf file:

server {

    root /srv/www/mysite.com/public_html;
    server_name mysite.com

    location / {
        try_files $uri $uri/ /index.php/$request_uri;
        autoindex on; # just for debugging...
    }

    location ~ .php($|/) {
        set $script $uri;
        if ($uri ~ "^(.+.php)(/.+)") {
            set $script $1;
        }
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$script;
        fastcgi_intercept_errors on;
        fastcgi_pass  unix:/var/run/php5-fpm.sock;
    }

}

My answer:


Your configuration is missing index index.php;.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.