解析php:nginx和php它们在配置之前,它们是不能自动地联系在一起的,需要手动去更改配置文件,然后让它们两者产生联系,然后正常地去执行php,去解析php的网站;像apache是调用了一个libphp5.so一个模块,实现了解析php,虽然生成了模块,要想去解析它,还是要编辑配置文件的,nginx也是一样的

## 编辑nginx配置文件

[root@aminglinux ~]# vim /usr/local/nginx/conf/nginx.conf

location / {

           root   /usr/local/nginx/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  /usr/local/nginx/html$fastcgi_script_name;

           include        fastcgi_params;

 }

解释说明:

/usr/local/nginx/html是配置的web网站根目录。也就是说你的php要写在这个地方,才能够找到,要不然就会是404

WEBRESOURCEe4ee9c320877581b3feea48107044

## 检测语法并重新加载

[root@aminglinux ~]# /usr/local/nginx/sbin/nginx -t

[root@aminglinux ~]# /usr/local/nginx/sbin/nginx -s reload

## nginx的欢迎页面

WEBRESOURCEa83a5ef0996874ceaeb883323b8d4

解释说明:

其实是/usr/local/nginx/html/index.html

## 在/usr/local/nginx/html/下面写一个info.php

[root@aminglinux ~]# vim /usr/local/nginx/html/info.php

<?php

phpinfo();

?>

WEBRESOURCEf0299203d15c45b31e83017733870

## 也可以用curl检测是否解析成功

[root@aminglinux ~]# curl localhost/info.php