百度空间 | 百度首页 
 
查看文章
 
Nginx + PHP + FastCGI
2007-06-20 14:26

Nginx 是一个轻量级的 http server,也可作为 proxy server 使用,由一个俄罗斯哥们儿开发并在一些高负载的站点上跑了2年多。许多人用它来搭建 Rails 应用,有的评测性能已经超过 lighty。Nginx 能快速响应静态页面的请求,支持 fastcgi、ssl、virtual host、rewrite、HTTP Basic Auth、Gzip 等,功能比较完备,配置文件也是类似 lighty 那种很简介的形式。

Nginx 和 PHP 一起应用应该也是个不错的搭配:
1. 第一步安装 Nginx,最新版本是 0.5.5,配置:

./configure 
         --sbin-path=/usr/local/nginx/nginx
         --conf-path=/usr/local/nginx/nginx.conf
         --pid-path=/usr/local/nginx/nginx.pid
         --with-http_ssl_module

如果是需要 rewrite 模块的话,系统需要有 pcre-devel 类似的包,然后就是 make ; make install 。

2. 然后需要 PHP 有 fastcgi 的支持,编译的时候带上 --enable-fastcgi 这个选项。

3. 运行FastCGI server,有2种方法,一种是运行 PHP 自带的 FastCGI server,可以用类似的脚本来执行;一种是使用 spawn-fcgi 这样的工具(lighty网站上有下载),推荐用后者,使用很方便:

spawn-fcgi -a 127.0.0.1 -p 9000 -u jason -f /usr/bin/php-cgi 
4. 配置 Nginx,将 nginx.conf 中关于 PHP 支持那段按实际情况稍作修改即可:
location ~ .php$ {
     fastcgi_pass    127.0.0.1:9000;
     fastcgi_index   index.php;
     fastcgi_param   SCRIPT_FILENAME   /usr/local/nginx/html$fastcgi_script_name;
     include         conf/fastcgi_params;
}

那个 include 的 conf 目录可以在源码包里复制过来。

5. 启动 nginx,访问 localhost,能看到一个大大的 Welcome to nginx!,再跑几个 PHP 应用试试。


类别:Linux | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu