算是原创。转载请注明此地址,随着对NGINX认知的深入,此文会不定期更新或是修正。

引用:
Nginx ("engine x") 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过两年半了。Igor 将源代码以类BSD许可证的形式发布。


phpcgi脚本参考[url]http://hi.baidu.com/jackbillow/blog/item/c60ccc02b33caa0d4afb51f6.html[/url]

安装参考:[url]http://blog.s135.com/read.php/314.htm[/url]  呵呵,照做总没有成功。试了n多次。后来改变了一些方法。有时 间另文写出!

安装参考:[url]http://www.howtoforge.com/lemp_nginx_mysql_php_ubuntu_debian[/url] 我一直用的是centos,为了使用NGINX。一度想换个LINUX OS发行版本。还好。用了GOOGLE终于搞定了。

针对redhat的rpm包:[url]http://dl.activeby.net/rpms/RPMS/[/url] (NGINX的版本是nginx-0.5.32) 因为机器能连网。我就直接用yum(NGINX的版本是nginx-0.5.33-2.el5)啦。呵呵,你也可以下载后,安装。

安装参考:[url]http://shiningray.cn/linux-shang-pei-zhi-nginx-php5-fastcgi.html[/url]



1、安装环境CentOs 5.1
[root@nginx-freetds html]# uname -a
Linux nginx-freetds 2.6.18-53.el5 #1 SMP Mon Nov 12 02:22:48 EST 2007 i686 i686 i386 GNU/Linux
2、系统安装时定制安装mysql了。当然也可以采用yum install的方式安装。同时。安装了一些开发工具。呵呵,如果使用yum install的方式。亦可不在安装系统时安装。



开始安装:
1、启用CENTOS的额加包。如果不安装,可能会出现不能安装NGINX的问题。

[root@nginx-freetds ~]# rpm -Uvh [url]http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-2.noarch.rpm[/url]
Retrieving [url]http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-2.noarch.rpm[/url]
warning: /var/tmp/rpm-xfer.4hD87B: Header V3 DSA signature: NOKEY, key ID 217521f6
Preparing...                ########################################### [100%]
   1:epel-release           ########################################### [100%]
[root@nginx-freetds ~]#

2、安装NGINX

[root@nginx-freetds ~]#  yum install -y nginx
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
epel                      100% |=========================| 1.1 kB    00:00    
Reading repository metadata in from local files
primary.xml.gz            100% |=========================| 513 kB    00:04    
################################################## 1595/1595
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for nginx to pack into transaction set.
nginx-0.5.33-2.el5.i386.r 100% |=========================| 8.3 kB    00:00    
---> Package nginx.i386 0:0.5.33-2.el5 set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
nginx                   i386       0.5.33-2.el5     epel              286 k

Transaction Summary
=============================================================================
Install      1 Package(s)        
Update       0 Package(s)        
Remove       0 Package(s)        

Total download size: 286 k
Downloading Packages:
(1/1): nginx-0.5.33-2.el5 100% |=========================| 286 kB    00:02    
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 217521f6
Importing GPG key 0x217521F6 "Fedora EPEL <[email][email protected][/email]>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: nginx                        ######################### [1/1]

Installed: nginx.i386 0:0.5.33-2.el5
Complete!
[root@nginx-freetds ~]#


3、安装后,NGINX的配置文件位于:
[root@nginx-freetds ~]# ll /etc/nginx/
total 28
-rw-r--r-- 1 root root 2837 Nov 12 16:11 koi-utf
-rw-r--r-- 1 root root 2223 Nov 12 16:11 koi-win
-rw-r--r-- 1 root root 2991 Nov 12 16:11 mime.types
-rw-r--r-- 1 root root 2991 Nov 12 16:11 mime.types.default
-rw-r--r-- 1 root root 2753 Nov 12 16:11 nginx.conf
-rw-r--r-- 1 root root 2753 Nov 12 16:11 nginx.conf.default
-rw-r--r-- 1 root root 3610 Nov 12 16:11 win-utf

安装后,NGINX的网站目录位于:
[root@nginx-freetds ~]#

4、配置Nginx的PHP FastCGI
请将以下内容保存为fastcgi.conf文件,保存于/usr/share/nginx下,它为我们的FastCGI模块设置了基本的环境变量:


[root@nginx-freetds ~]# ll /usr/share/nginx/
total 4
drwxr-xr-x 2 root root 4096 Jan 20 19:58 html
[root@nginx-freetds ~]# vi /usr/share/nginx/fastcgi.conf

输入:
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

为什么会是在这个下面。这是我经过多次失败之后的总结,当然也可以改在其它的位置。只需在第10步中更改include 后的路径便可:
[root@nginx-freetds ~]# service nginx restart
Stopping nginx: [FAILED]
Starting nginx: 2008/01/20 00:05:32 [emerg] 15038#0: glob() "/usr/share/nginx/./fastcgi.conf" failed (2: No such file or directory) in /etc/nginx/nginx.conf:123
[FAILED]

5、接下来安装PHP,加上php-cli 以便在/usr/bin/ 生成php-cgi。这个很重要。还需要使用到它。
[root@nginx-freetds ~]# yum install -y php php-cli
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
base                      100% |=========================| 1.1 kB    00:00    
updates                   100% |=========================|  951 B    00:00    
addons                    100% |=========================|  951 B    00:00    
extras                    100% |=========================| 1.1 kB    00:00    
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for php to pack into transaction set.
php-5.1.6-15.el5.i386.rpm 100% |=========================|  18 kB    00:00    
---> Package php.i386 0:5.1.6-15.el5 set to be updated
---> Downloading header for php-cli to pack into transaction set.
php-cli-5.1.6-15.el5.i386 100% |=========================|  17 kB    00:00    
---> Package php-cli.i386 0:5.1.6-15.el5 set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
php                     i386       5.1.6-15.el5     base              1.2 M
php-cli                 i386       5.1.6-15.el5     base              2.3 M

Transaction Summary
=============================================================================
Install      2 Package(s)        
Update       0 Package(s)        
Remove       0 Package(s)        

Total download size: 3.5 M
Downloading Packages:
(1/2): php-5.1.6-15.el5.i 100% |=========================| 1.2 MB    00:04    
(2/2): php-cli-5.1.6-15.e 100% |=========================| 2.3 MB    00:06    
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897
Importing GPG key 0xE8562897 "CentOS-5 Key (CentOS 5 Official Signing Key) <[email][email protected][/email]>" from [url]http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5[/url]
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: php-cli                      ######################### [1/2]
  Installing: php                          ######################### [2/2]

Installed: php.i386 0:5.1.6-15.el5 php-cli.i386 0:5.1.6-15.el5
Complete!
[root@nginx-freetds ~]#

查看下:
[root@nginx-freetds ~]# locate php-cgi
/usr/bin/php-cgi
呵呵,已生成php-cgi啦。

show 下安装后的php组件:

[root@nginx-freetds ~]# rpm -aq |grep php
php-5.1.6-15.el5
php-pdo-5.1.6-15.el5
php-common-5.1.6-15.el5
php-mysql-5.1.6-15.el5
php-cli-5.1.6-15.el5


6、接下来安装lighthttp以得到spawn-fcgi以此来控制php-cgi进程运行

[root@nginx-freetds ~]# yum install -y lighttpd-fastcgi
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
epel                      100% |=========================| 1.1 kB    00:00    
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for lighttpd-fastcgi to pack into transaction set.
lighttpd-fastcgi-1.4.18-1 100% |=========================| 9.6 kB    00:00    
---> Package lighttpd-fastcgi.i386 0:1.4.18-1.el5 set to be updated
--> Running transaction check
--> Processing Dependency: lighttpd = 1.4.18 for package: lighttpd-fastcgi
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for lighttpd to pack into transaction set.
lighttpd-1.4.18-1.el5.i38 100% |=========================|  21 kB    00:00    
---> Package lighttpd.i386 0:1.4.18-1.el5 set to be updated
--> Running transaction check
--> Processing Dependency: liblua-5.1.so for package: lighttpd
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for lua to pack into transaction set.
lua-5.1.2-1.el5.i386.rpm  100% |=========================| 6.8 kB    00:00    
---> Package lua.i386 0:5.1.2-1.el5 set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
lighttpd-fastcgi        i386       1.4.18-1.el5     epel               45 k
Installing for dependencies:
lighttpd                i386       1.4.18-1.el5     epel              373 k
lua                     i386       5.1.2-1.el5      epel              225 k

Transaction Summary
=============================================================================
Install      3 Package(s)        
Update       0 Package(s)        
Remove       0 Package(s)        

Total download size: 643 k
Downloading Packages:
(1/3): lighttpd-1.4.18-1. 100% |=========================| 373 kB    00:01    
(2/3): lighttpd-fastcgi-1 100% |=========================|  45 kB    00:00    
(3/3): lua-5.1.2-1.el5.i3 100% |=========================| 225 kB    00:01    
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: lua                          ######################### [1/3]
  Installing: lighttpd                     ######################### [2/3]
  Installing: lighttpd-fastcgi             ######################### [3/3]

Installed: lighttpd-fastcgi.i386 0:1.4.18-1.el5
Dependency Installed: lighttpd.i386 0:1.4.18-1.el5 lua.i386 0:5.1.2-1.el5
Complete!
[root@nginx-freetds ~]# updatedb
[root@nginx-freetds ~]# locate spawn-fcgi
/usr/bin/spawn-fcgi
/usr/share/man/man1/spawn-fcgi.1.gz
[root@nginx-freetds ~]#

OK,spawn-fcgi被安装成命令行式了。成功。