nginx + php fpm -> 404 php pages - file not found

Posted by Mahesh on Server Fault See other posts from Server Fault or by Mahesh
Published on 2013-10-20T20:26:37Z Indexed on 2013/10/20 21:56 UTC
Read the original article Hit count: 233

Filed under:
|
*2037 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

 server {
    listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default ipv6only=on; ## listen for ipv6

    server_name .site.com;
    root /var/www/site;
    error_page 404 /404.php;
    access_log /var/log/nginx/site.access.log;
    index index.html index.php;


    if ($http_host != "www.site.com") {
             rewrite ^ http://www.site.com$request_uri permanent;
   }

    location ~* \.php$ {
        fastcgi_index   index.php;
        fastcgi_pass    127.0.0.1:9000;
        #fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
         fastcgi_buffer_size 128k;
         fastcgi_buffers 256 4k;
         fastcgi_busy_buffers_size 256k;
         fastcgi_temp_file_write_size 256k;
         fastcgi_read_timeout 240;

        include         /etc/nginx/fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }

    location ~ /\. {
        access_log off;
        log_not_found off;
        deny all;
    }

   location ~ /(libraries|setup/frames|setup/libs) {
       deny all;
       return 404;
   }

    location ~ ^/uploads/(\d+)/(\d+)/(\d+)/(\d+)/(.*)$ {
             alias /var/www/site/images/missing.gif; 
#i need to modify this to show only missing files. right now it is showing missing for all the files.

    }

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
            access_log off;
            expires 20d;
    }

    location /user_uploads/ {
            location ~ .*\.(php)?$
            {
                deny all;
            }
    }

    location ~ /\.ht {
             deny  all;
    }

}

php-fpm config is default and is not touched.

The problem is little strange for me. Error pages are showing File not found only if they are .php files. Other error files are clearly calling the 404.php file

site.com/test => calls 404.php
site.com/test.php => File not found.

I am searching and making changes. but it hasn't solved the problem.

© Server Fault or respective owner

Related posts about nginx

Related posts about php-fpm