对于nginx配置文件中的fastcgi_param相关参数的理解

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

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

一开始以下:ubuntu

        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;php7

这个配置的意思是 在浏览器中访问的.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 报错,缘由尚未找到unix