今天在ubuntu中搭建LNMP的时候,遇到了一个问题 在浏览器中访问.php文件的时候,nginx不能正常解析,页面只是空白,后来百度了一下,发现了问题

在nginx的配置文件nginx.conf中的server配置段:

一开始如下:

        location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
                include fastcgi_params;
        #       fastcgi_pass 127.0.0.1:9000;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                fastcgi_index index.php;
        }

后来修改为如下:

        location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
                include fastcgi_params;
        #       fastcgi_pass 127.0.0.1:9000;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

唯一的区别是:加入了一行配置   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

这个配置的意思是 在浏览器中访问的.php文件,实际读取的是 $document_root(网站根目录)下的.php文件 -- 也就是说当访问127.0.0.1/index.php的时候,需要读取网站根目录下面的index.php文件,如果没有配置这一配置项时,nginx不回去网站根目录下访问.php文件,所以返回空白

配置项目中:include fastcgi_params; fastcgi_params 文件中含有各个nginx常量的定义,默认情况 SCRIPT_FILENAME = $fastcgi_script_name

注意:在测试中发现include fastcgi-php.conf 报错,原因还没有找到

  

 

相关文章:

  • 2022-01-09
  • 2022-01-22
  • 2022-12-23
  • 2021-04-26
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2021-09-17
  • 2021-05-11
相关资源
相似解决方案