Nginx 404 while it should just proxy pass to php-fpm

I have a simple nginx config that used to pass all requests to /site/index.php. After upgrading to ubuntu 12.04 this config doesn’t work anymore.

server {
    listen   80;
    server_name site.com;
    root /site/;
    access_log  /var/log/nginx/site.log;

    location / {
             fastcgi_pass    127.0.0.1:9000;
             fastcgi_index   index.php;
             fastcgi_param   SCRIPT_FILENAME /site/index.php;
             include         fastcgi_params;
    }
}

The rule fastcgi_param SCRIPT_FILENAME /site/index.php; used to send everything matching ‘location /’ to index.php but now instead I get a 404 error.

This works

  • site/index.php

This doesn’t

  • site
  • site/folder

Any ideas ?

Answer

You don’t have an index specified in your config, try the next config instead:

server {
    listen   80;
    server_name site.com;
    root /site/;
    access_log  /var/log/nginx/site.log;

    location / {
             index index.php index.html;
     }

    location ~ \.php$ {
             fastcgi_pass    127.0.0.1:9000;
             fastcgi_index   index.php;
             fastcgi_param   SCRIPT_FILENAME /site/index.php;
             include         fastcgi_params;
    }
}

Attribution
Source : Link , Question Author : user17886 , Answer Author : Logic Wreck

Leave a Comment