栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > 服务器

解决启动php-fpm后访问不到php文件的办法

服务器 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

解决启动php-fpm后访问不到php文件的办法

问题场景:

  1. linux系统
  2. nginx服务器
  3. 安装好了fpm的php7
  4. 在nginx的web目录下新建了index.php文件,内容为phpinfo()函数。(如果是源码安装,位置一般为 /usr/local/nginx/html/index.php)

nginx经过了简单的配置,开始试验是否可以支持php

  location / {
   root html;
   index index.html index.htm index.php;
  }
 
  location ~ .php$ {
   root   html;
   fastcgi_pass 127.0.0.1:9000;
   fastcgi_index index.php;
   fastcgi_param script_FILENAME /scripts$fastcgi_script_name;
   include  fastcgi_params;
  }

在浏览器访问 localhost/index.php

结果为 File not found.

这时候我们查看nginx的错误日志,错误日志的主要内容为 FastCGI sent in stderr: "Primary script unknown"

经过分析+搜索前辈经验得出结论,nginx的配置文件无法识别/scripts路径,所以我们将配置文件中的/scripts改为$document_root,或者web目录的绝对路径。更改后的配置文件如下:

  location ~ .php$ {
   root   html;
   fastcgi_pass 127.0.0.1:9000;
   fastcgi_index index.php;
   fastcgi_param script_FILENAME $document_root$fastcgi_script_name;
   include  fastcgi_params;
  }

重启nginx服务器,已经可以正确显示phpinfo()的内容了。

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/182225.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号