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;本人测试过也是可以的。

3964

被折叠的 条评论
为什么被折叠?



