File not found 錯誤 nginx

這個錯誤很常見,很明顯找不到文件。php

緣由是php-fpm找不到SCRIPT_FILENAME裏執行的php文件,因此返回給nginx 404 錯誤。html

那麼兩種狀況要麼文件真的不存在,要麼就是路徑錯誤。nginx

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外面試試看或者在php-fpm

location ~ \.php$ {}

裏面加上root.spa

若是文件真的不存在的話,由於nginx檢查$uri是否是.php結尾,不檢查是否是存在,因此找不到時候就返回404錯誤。「No input file specified」htm

若是是這樣的話,在配置文件種用try_files就能夠檢查是否存在了。blog

不存在就返回404.ip

location ~ .php$ {
 try_files $uri =404;
 fastcgi_pass 127.0.0.1:9000;
 fastcgi_index index.php;
 ...
}
相關文章
相關標籤/搜索