尝试了一把nginx和php-fastcgi

尝试了一把nginx和php-fastcgi,感觉速度好像是快了点,也许是错觉,不过以nginx四百多K的体积能做到这样我觉得相当不错,简要写一下配置。首先当然是安装nginx,不管你是编译还是二进制,这个没有太多可以说的,差不多,然后呢是编译php,在apache下面安装习惯了,一直没把–with-apxs去掉,我就说怎么一直不给生成那个php-cgi文件呢,搞了半天是不能同时使用的,靠,configure的时候又不提示一下,无效开关应该要提示才对的嘛,接下来是修改一下php.ini,修改说明如下:

; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP’s
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
; this to 1 will cause PHP CGI to fix it’s paths to conform to the spec. A setting
; of zero causes PHP to behave as before. Default is 1. You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
cgi.fix_pathinfo=1

倒数第二步呢,当然就是启动php-cgi server,使用命令行启动:php-cgi -b 127.0.0.1:9000 使得其监听在本地9000端口,最后一步就是修改nginx配置了,MMP的配置文件里面居然还有语法,所以不流行撒,看apache的配置都形成了一个规范,配置文件是这样的,其它部分我跳过了,不用修改,只写下修改的虚拟主机部分,我们以bbs.hnair.com为例:

###############bbs.hnair.com######哈利路亚#########
server {
listen 80;
server_name bbs.hnair.com;
location / {
index index.html index.htm index.php;
root /usr/local/www/bbs.hnair.com;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/www/bbs.hnair.com/$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
}
}

当然了,一些细小的配置,例如gzip压缩,rewrite,用户验证等等,我再研究下了来,可是想了想,按照web应用的细分,这种结构是为了极大负载设计,那么就不应该有rewrite,用户验证这些东西,simple is the best~