[Linux Web] 安装新的 nginx 使用 php 加 fastcgi
转载本站文章请注明,转载自:扶凯[http://www.php-oa.com]
本文链接: http://www.php-oa.com/2008/12/20/nginx-php-php-fpm-fastcgi.html
Nginx 本身就不用介绍了,目前使用 FastCGI 是最流行的模式.现在不少网站使用.我来介绍一个简单的安装方法.
先要使用第三方的源,默认的源是不存在最新的 php 的,需要 php 5.3.3 以上才有 php-fpm,所以一定要安装这些源..
配置最新 PHP 的源
如果是 CentOS 6 和 Red Hat (RHEL) 6 的 Remi 源
rpm -Uvh http://download.fedora.redhat.com/pub/epel/6/i386/epel-release-6-5.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
如果是 CentOS 5 和 Red Hat (RHEL) 5 的 Remi 源
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
配置 Nginx 的源
我们需要建一个新的源文件,编辑 /etc/yum.repos.d/nginx.repo 就可以了.加入如下内容
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
安装最新的 Nginx 和 PHP(php-fpm)
安装最新的 Nginx 和 PHP .还有支持启动 FastCGI 的 php-fpm 的功能.其它都是 PHP 的一些模块了.
yum --enablerepo=remi install nginx php php-fpm php-common \ php-pear php-pdo php-mysql php-pgsql php-pecl-memcache php-gd \ php-mbstring php-mcrypt php-xml
安装 MYSql 也需要使用这个的源才行
yum --enablerepo=remi install mysql mysql-server
配置 Nginx 和 PHP-FPM
在 Nginx 加,给这些下面的注掉的内容打开,让 php 的文件支持使用 fastcgi 来通信就行了.
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
测试 Nginx 和 PHP-FPM
我们需要确认 fastcgi 是否能正常的使用,所以需要在,上面的 /usr/share/nginx/html 中加入 phpinfo.php 的测试文件.
<?php
phpinfo();
?>
这时只要打开 url 来测试这个 phpinfo.php 文件是否能正常的显示就行了.
启动和永久启动 Nginx 和 PHP-FPM
我们一定不想下次 Nginx 和 PHP-FPM 在也启动不了啦,所以我们需要加入启动中去.让系统启动后就能自动启动这些.
service nginx start service php-fpm start chkconfig --add nginx chkconfig --levels 235 nginx on chkconfig --add php-fpm chkconfig --levels 235 php-fpm on



















location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
博主,请教一下,上面配置中的 .* 是什么意思呢?
如果我图片或者JS在不同的目录,也有可能是/下很多目录,例如:
/test1/test2/image/1.jpg
/test1/test2/SKIN/1.js
那这样的目录结构可以使用.*生效吗?
.*是任何一个和多个字符
第二个问题.能生效,这个正则比的是最后面的字符.所以前面的目录可以不考虑.