Clean URLs and php extension on nginx

Solution 1:

Did you try with the rewrite directive? For example:

location / {
    try_files $uri $uri/ @extensionless-php;
    index index.html index.htm index.php;
} 

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
}

location @extensionless-php {
    rewrite ^(.*)$ $1.php last;
}

Source: http://www.tweaktalk.net/60/nginx-remove-php-file-extension-from-url

Solution 2:

try_files always executes in current context, that's why it serves your php-scripts as plain files - current location lacks fastcgi_pass. try_files is evil because instead of straightforwardness it creates questionable blocks, avoid it.

In the same time regexp-locations have priority over ordinary locations, that's why nothing changes when you reverse the order.

Personally I think that hiding .php extensions from address bar is useless, as it adds more code to the configuration file.