码迷,mamicode.com
首页 > Web开发 > 详细

nginx解析php

时间:2017-01-07 08:21:37      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:nginx

首先在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 
<?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字样,则表明解析成功!

本文出自 “自定义” 博客,谢绝转载!

nginx解析php

标签:nginx

原文地址:http://zidingyi.blog.51cto.com/10735263/1889893

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!