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

吾爱主题 阅读:177 2021-12-09 15:35:00 评论:0

问题场景:

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

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

?
1 2 3 4 5 6 7 8 9 10 11 12 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目录的绝对路径。更改后的配置文件如下:

?
1 2 3 4 5 6 7 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()的内容了。

总结

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

可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

【腾讯云】云服务器产品特惠热卖中
搜索
标签列表
    关注我们

    了解等多精彩内容