I'm trying to get Nginx to handle php files without an extension (i.e. to handle http://localhost/sample the same way it would handle http://localhost/sample.php).
This is my site configuration:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name localhost;
root /var/www;
index index.html index.php;
location ~ \.(hh|php)$ {
fastcgi_keep_conn on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location / {
try_files $uri $uri/ $uri.html @extensionless =404;
}
location @extensionless {
rewrite ^(.*)$ $1.php last;
}
}
As far as I know it should do the trick. However - it doesn't. Trying http://localhost/sample just gets me to a 404 page (whereas http://localhost/sample.php works fine).
When turning on debugging, I see the following in the logs:
2015/07/19 15:37:00 [debug] 4783#0: *1 http script var: "/sample"
2015/07/19 15:37:00 [debug] 4783#0: *1 trying to use file: "/sample" "/var/www/sample"
2015/07/19 15:37:00 [debug] 4783#0: *1 http script var: "/sample"
2015/07/19 15:37:00 [debug] 4783#0: *1 trying to use dir: "/sample" "/var/www/sample"
2015/07/19 15:37:00 [debug] 4783#0: *1 http script var: "/sample"
2015/07/19 15:37:00 [debug] 4783#0: *1 http script copy: ".html"
2015/07/19 15:37:00 [debug] 4783#0: *1 trying to use file: "/sample.html" "/var/www/sample.html"
2015/07/19 15:37:00 [debug] 4783#0: *1 trying to use file: "@extensionless" "/var/www@extensionless"
2015/07/19 15:37:00 [debug] 4783#0: *1 trying to use file: "=404" "/var/www=404"
Which is weird. It basically looks like @extensionless is treated as a plain filename (instead of a location leading to a rewrite of the URL).
What am I missing? :) Thanks!