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页面也是同样的解决办法。



猜你喜欢

转载自blog.csdn.net/weixin_40555670/article/details/80305601