nginx实例配置过程:
直接从网络上下载rpm安装包:nginx-0.6.39-4.el4.i386.rpm
直接安装 rpm -ivh nginx-0.6.39-4.el4.i386.rpm  在RHEL4.0可以直接安装,无需其他安装包依赖
然后是配置/etc/nginx/nginx.conf
具体配置内容:
user  www www;           #用户 用户组
worker_processes  2;     #这里根据CPU个数设置,但是可以实际的多一些

error_log   /var/log/nginx/error.log;       #这个是日志的位置
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;             #这个默认就可以


events {
    worker_connections  2048;            #可以设置稍微大一些 1024的倍数
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] $request '
                      '"$status" $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8080;            #这里是监听端口
        server_name  localhost;

        #charset koi8-r;

        #access_log  /var/log/nginx/host.access.log  main;

        location / {
            root   /var/www/html/;    #这里是网站服务器的根目录,记得如果测试,请在该目录下面touch index.html 生成一个index.html 文件
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {                   #这里是通过fastcgi来为NGINX开始php服务功能 
            root           /var/www/html/;    #设置目录
            fastcgi_pass   127.0.0.1:9000;    #设置监听端口
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
           include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}

光是安装nginx无法使用php 需要配置/etc/nginx/nginx.conf   其实就是把相应字段的#号去掉。
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {                   #这里是通过fastcgi来为NGINX开始php服务功能 
            root           /var/www/html/;    #设置目录   这个设置完成后,打开IE  http://192.168.133.128,默认会查找/var/www/html/index.php这个文件
            fastcgi_pass   127.0.0.1:9000;    #设置监听端口
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
           include        fastcgi_params;
        }
还需要安装软件spawn-fcgi-1.6.3-1.el4.i386.rpm,这个文件算是lighttp下面的一个,主要用来启动php-cgi
还需要php安装是cgi模式,这样会生成php-cgi文件
    我直接使用rhel4.0,里面默认安装的是PHP4.0,并没有php-cgi文件(直接安装php-cli-5.3.6-3.el4.remi.i386.rpm文件好像也不可行)
因此直接删除php4.0 安装PHP 5.3.6 (cli) (built: Apr 15 2011 20:47:07)
    具体删除php4.0就不细说了,查看安装的php相关文件 rpm -qa|grep php ,然后删除所有相关文件
    下载php5.3.6相关文件,列表如下:
-rw-r--r--  1 root root   1282958 Mar  8 16:11 mysql-libs-5.5.11-1.el4.remi.i386.rpm
-rw-r--r--  1 root root   2020731 Mar  8 16:11 MySQL-shared-5.5.11-1.rhel4.i386.rpm
-rw-r--r--  1 root root   1350089 Mar  8 15:54 php-5.3.6-3.el4.remi.i386.rpm
-rw-r--r--  1 root root   2648988 Mar  8 15:40 php-cli-5.3.6-3.el4.remi.i386.rpm
-rw-r--r--  1 root root    985199 Mar  8 15:46 php-common-5.3.6-3.el4.remi.i386.rpm
-rw-r--r--  1 root root    628187 Mar  8 15:59 php-devel-5.3.6-3.el4.remi.i386.rpm
-rw-r--r--  1 root root     53092 Mar  8 15:56 php-ldap-5.3.6-3.el4.remi.i386.rpm
-rw-r--r--  1 root root    149426 Mar  8 15:56 php-mysql-5.3.6-3.el4.remi.i386.rpm
-rw-r--r--  1 root root    113652 Mar  8 16:05 php-pdo-5.3.6-3.el4.remi.i386.rpm
-rw-r--r--  1 root root    306385 Mar  8 15:57 php-pear-5.1.1-1.1.rhel4.ct.i386.rpm
-rw-r--r--  1 root root    197728 Mar  8 16:07 sqlite-3.3.6-0.3.el4.i386.rpm
    
     正常情况下php-pear-5.1.1-1.1.rhel4.ct.i386.rpm 无法安装,需要[root@bogon test]# rpm -ivh php-pear-5.1.1-1.1.rhel4.ct.i386.rpm
error: Failed dependencies:
        php = 5.1.1-1.1.rhel4.ct is needed by php-pear-5.1.1-1.1.rhel4.ct.i386
     所以这个我干脆就没有安装
     安装完以上这些后,就直接查找php-cgi文件
    [root@bogon test]# find / -name 'php-cgi'
    /usr/bin/php-cgi
然后使用命令:
     [root@bogon test]# spawn-fcgi -a 127.0.0.1 -p 9000 -u www -f /usr/bin/php-cgi
     spawn-fcgi: child spawned successfully: PID: 7980
     查看php-cgi是否启动:
     [root@bogon test]# ps -aux |grep php-cgi
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.3/FAQ
www       7980  0.1  0.2 31552 5164 ?        Ss   09:39   0:00 /usr/bin/php-cgi
root      8009  0.0  0.0  4800  564 pts/1    R+   09:40   0:00 grep php-cgi
     这里看到OK了,建议OK后重新启动nginx   service nginx restart
    

 

配置Nginx 配置虚拟主机
vi /etc/nginx/nginx.conf
     具体配置如下:请把相关行的#去掉
   # another virtual host using mix of IP-, name-, and port-based configuration
     82     #
     83     server {
     84         listen       8000;         ####虚拟主机监听的端口8000
     85     #    listen       somename:8080;
     86     server_name  somename  alias  another.alias;
     87
     88      location / {
     89        root  /var/www/html/www;     ####虚拟主机目录
     90             index  index.html index.htm;
     91         }
     92     }
     93
配置完后重新启动 service nginx restart
     然后直接打开网页  http://192.168.133.128:8000
     网页直接打开的是/var/www/html/www/index.htm   说明虚拟主机配置成功。
     也可以通过netstat -antup |grep nginx
tcp        0      0 0.0.0.0:8000                0.0.0.0:*                   LISTEN      19013/nginx.conf    ####这个说明 虚拟主机已经OK
tcp        0      0 0.0.0.0:8080                0.0.0.0:*                   LISTEN      19013/nginx.conf    

 


问题1:
      打开IE,直接输入地址***.php:    屏幕显示 No input file specified
      解决方案:
     方法1首先php.ini的配置中
        将这条cgi.fix_pathinfo=1前面的;去掉    后再重启php-cgi,php显示正常
     记得修改了php.ini要重启fastcgi服务。 我这里单修改这个,还是不成,又用了方法2,才OK。
     方法2
      nginx中的配置有些麻烦
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
      每个虚机要根据自己不通的虚机设置不能的目录,要保证这个路径正确。
      fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;不能在fastcgi_pass 127.0.0.1:9000;的前面。

      打开:http://192.168.133.128:8080/index.php 

      显示如下:this is php web test one !!!!!

 

问题2:
     spawn-fcgi -a 127.0.0.1 -p 9000 -u www -f /usr/bin/php-cgi  使用这条命令提示如下:
     spawn-fcgi: child exited with: 126   当时使用PHP4.0 ,系统中没有php-cgi这个文件
     spawn-fcgi: child exited with: 13    使用PHP5.3.6 ,命令中多了-C 64 出错
     spawn-fcgi: child exited with: 2      使用PHP5.3.6 ,命令中多了-C 64 出错