Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Try_files does not hit PHP ( NginX configuration)

Tags:

php

nginx

Below is my nginx.conf.

In case of non existing files /index.php is served fine.

But when my URL is /foo/bar => /foo/bar/index.php is served as PHP source code via download.

Any ideas?

try_files $uri $uri/ $uri/index.php /index.php;

location ~ \.php$ { 
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}
like image 930
Benjamin Harel Avatar asked Aug 23 '12 12:08

Benjamin Harel


2 Answers

Solution was to add index index.php

    index index.php

    try_files $uri $uri/ $uri/index.php /index.php;

    location ~ \.php$ { 
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
like image 114
Benjamin Harel Avatar answered Nov 15 '22 17:11

Benjamin Harel


My config

index index.html index.htm index.php;
location ~ \.php$ {
        fastcgi_pass unix:/tmp/php-fpm.sock;
        include fastcgi_params;
      }

reload nginx and fastcgi both

like image 39
amitchhajer Avatar answered Nov 15 '22 18:11

amitchhajer