首先在nginx配置文件打开如下几行的注释: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;

}

只需要把SCRIPT_FILENAME的文件位置更改为如上所示即可

然后检测nginx的配置文件是否正确,注意每一次更改配置文件后,都要进行此项检测![root@lnmp html]# /usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

然后重新加载配置文件/usr/local/nginx/sbin/nginx -s reload

创建php文件:cd /usr/local/nginx/html/

创建文件内容如下:

cat 2.php

echo "php works";

?>

用curl解析刚创建的php文件:[root@lnmp html]# curl localhost/2.php

php works

说明已经可以正常解析php文件了!

也可以在浏览器中输入命令解析,http://192.168.1.123/2.php

若出现php works字样,则表明解析成功!

更多推荐