设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 数据 手机
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php-fpm启动访问不到php文件是咋回事呢?

发布时间:2022-12-15 08:38 所属栏目:121 来源:互联网
导读:
导读:跟大家讲解下有关php-fpm启动访问不到php文件是怎么回事呢?的内容 ,相信小伙伴们对这个话题应该有所关注吧,小编也收集到了相关资料,希望小伙伴们看了有所帮助。 问题场景: linux系统 nginx服务器 安装好了fpm的php7 在nginx的web目录下新建了index.php
  跟大家讲解下有关“php-fpm启动访问不到php文件是怎么回事呢?”的内容 ,相信小伙伴们对这个话题应该有所关注吧,小编也收集到了相关资料,希望小伙伴们看了有所帮助。
 
  问题场景:
 
  linux系统
 
  nginx服务器
 
  安装好了fpm的php7
 
  在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()的内容了。
 
 

(编辑:ASP站长网)

    网友评论
    推荐文章
      热点阅读