nginx + php fpm->404 php 页面-找不到文件

nginx + php fpm->404 php 页面-找不到文件
*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 配置是默认的,没有受到影响。

这个问题对我来说有点奇怪。显示错误页面文件未找到只有当它们是 .php 文件时才会发生错误。其他错误文件显然调用了 404.php 文件

site.com/test => 调用 404.php
site.com/test.php => 文件未找到。

我正在搜索并做出改变。但问题并没有得到解决。

答案1

fastcgi_intercept_errors on

它解决了问题

答案2

location ~ \.php {
    ..
    try_files $uri =404;
    ..
}

在 php 位置块中添加此项以告诉 nginx 在向 FastCGI 发送任何请求之前检查文件是否存在。

相关内容