0

I am basically trying to implement the Apache MultiViews behaviour so that my URLs do not require the .php extension.

As far as I can see from other questions answered here on Server Fault, I should have this problem sorted, but something is clearly wrong in my nginx config.

The behaviour is almost correct;

  • I can browse to /path/to/app/ and the index.php file is correctly parsed
  • I can browse to /path/to/app/function.php and the file is correctly parsed
  • I can browse to /path/to/app/media/some.jpg and it is served as static content
  • If I browse to /path/that/doesnt/exist I get a 404 as expected

However, if I browse to /path/to/function the try_files directive correctly matches it to function.php but downloads it as a static file.

Here is the config file:

server { listen 80; server_name app; root /path/to/app; index index.php index.html index.htm; access_log /var/log/nginx/access.log; location / { allow all; try_files $uri $uri/ $uri.php =404; } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; } location ~ /\.ht { deny all; } } 

1 Answer 1

1

Looks like I was just misunderstanding the way try_files works; the =404 was not required and was causing nginx to not parse the file as php once it was matched. Removing it so that the line was just try_files $uri $uri/ $uri.php; fixed the issue

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.