1. 程式人生 > >nginx訪問php的 file not find問題和測試php時出現下載頁面解答

nginx訪問php的 file not find問題和測試php時出現下載頁面解答

在用nginx訪問php檔案時,遇到的返回狀態是file not find,最後查明原因是:php-fpm找不到SCRIPT_FILENAME裡執行的php檔案。

所以要在nginx配置檔案中做出以下修改:

vim  /usr/local/nginx/conf/nginx.conf

 location ~ \.php$ {
           root           html;
           try_files  $uri =404;                                ##檢查所要訪問的php檔案是否真的存在,若不存在返回404錯誤。
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  $document_root

$fastcgi_script_name;
           include        fastcgi_params;

         }

其中$document_root變數值不會因為修改了root指令的值或者移動檔案到別的目錄就出現fastcgi程序收到錯誤路徑(SCRIPT_FILENAME),因為SCRIPT_FILENAME可以隨著$doucument_root變化而變化。

出現下載php頁面也是同樣的解決辦法。