nginx上配置php

nginx上配置php

话说Nginx是俄罗斯工程师伊戈尔·西索夫(Igor Sysoev)在10年前创立的。Nginx 是一个轻量级的 http server,也可作为 proxy server 使用,由一个俄罗斯哥们儿开发并在一些高负载的站点上跑了多年。最近项目开发中用到php,于是研究了一下nginx上支持php的配置。

打开命令行终端,执行

[root@Host31 ~]# find / -name nginx.conf
/etc/nginx/nginx.conf
/root/nginx.conf
[root@Host31 ~]#

在/etc/nginx目录下修改nginx配置文件:

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        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;
        }

修改完成后重启nginx并且重新导入一下配置文件

[root@Host31 ~]# service nginx restart
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
[root@Host31 ~]# nginx -s reload
[root@Host31 ~]#

用浏览器访问一下php文件,成功了。我配置过几次失败,原因是
fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
document_root这个路径没有搞对,这个可以是nginx根目录的路径,我nginx服务器的根目录是
/usr/share/nginx/html
所以配置成
fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html/$fastcgi_script_name;
本人测试过也是可以的。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值