File not found 错误 nginx

这个错误很常见,很明显找不到文件。

原因是php-fpm找不到SCRIPT_FILENAME里执行的php文件,所以返回给nginx 404 错误。

那么两种情况要么文件真的不存在,要么就是路径错误。

location / {
        root   /var/www/example.com;
        index  index.html index.htm index.pl;
    }

如果配置文件这样的,那么明显不好,也就是在

location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME #document_root$fastcgi_script_name;
        include fastcgi_params;
    }

 这里的document就找不到document_root,所以可以把root放在location外面试试看或者在

location ~ \.php$ {}

里面加上root.

如果文件真的不存在的话,因为nginx检查$uri是不是.php结尾,不检查是不是存在,所以找不到时候就返回404错误。“No input file specified”

如果是这样的话,在配置文件种用try_files就可以检查是否存在了。

不存在就返回404.

location ~ .php$ {
 try_files $uri =404;
 fastcgi_pass 127.0.0.1:9000;
 fastcgi_index index.php;
 ...
}

 


posted on 2013-11-24 11:20  小浪鼓  阅读(27436)  评论(0编辑  收藏  举报

导航