通过yum搭建了下Centos下nginx+php + mysql的环境,但是访问localhost的时候,变成了下载文件。

把默认的nginx.conf里面的server段全部删除了,加载了虚拟主机配置的文件,发现虚拟主机配置文件中有个小地方没有改,无法解析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;
   }

/scripts修改成$document_root即可

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