I have a very simple PHP site:
.
├── about.php
├── index.php
├── project
│ ├── project_one.php
│ └── project_two.php
└── projects.php
And the following nginx config (only relevant parts shown):
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/path/to/php.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_intercept_errors on;
}
location / {
index index.php;
try_files $uri $uri/ $uri.php =404;
}
Hitting the /
works as expected. Hitting any of the http://my.site.com/{projects | about | project/*}
URLs should use try_files to hit the $uri.php
file, and pass it to PHP. But instead, the browser just downloads the PHP file itself.
I can get it to work by adding individual location directives for the above locations, like so:
location /projects {
try_files $uri $uri/ /$uri.php;
}
location /about {
try_files $uri $uri/ /$uri.php;
}
location /project {
try_files $uri $uri/ $uri.php;
}
But this is clearly not the way to do this.
What am I doing wrong???