首页 > 代码库 > nginx和FastCGI整合
nginx和FastCGI整合
nginx+fastcgi 安装
nginx安装:
# nginx-1.4.2.tar.gz
# libevent-1.4.13-stable.tar.gz
yum install pcre-devel openssl-devel
cd /usr/local/src
tar zxvf nginx-1.4.2.tar.gz
cd nginx-1.4.2
./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_gunzip_module --with-http_perl_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre
make
make install
#####################################################################
FastCGI的安装
yum install libxml2-devel openssl-devel bzip2-devel
cd /usr/local/src
tar zxvf php-5.4.13.tar.gz
cd /usr/local/src/ php-5.4.13
./configure --prefix=/usr/local/php --enable-fpm --with-openssl --enable-mbstring --enable-sysvshm --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl --enable-sockets --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml
--with-mysql --with-mysqli
make
make test
make install
#为php提供配置文件:
# cp php.ini-production /etc/php.ini
#为php-fpm提供Sysv init脚本,并将其添加至服务列表:
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
为php-fpm提供配置文件:
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
编辑php-fpm的配置文件:
# vim /usr/local/php/etc/php-fpm.conf
配置fpm的相关选项为你所需要的值,并启用pid文件(如下最后一行):
pm.max_children = 150
pm.start_servers = 8
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pid = /usr/local/php/var/run/php-fpm.pid
接下来就可以启动php-fpm了:
# service php-fpm start
使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):
# ps aux | grep php-fpm
######################################################
nginx和php-fpm配置
php的配置:
1. vi php-fpm.conf
listen_address 192.168.2.22:9000;
user nobody; 去掉注释
group nobody; 去掉注释
2.allow_clients 192.168.2.22
3.request_terminate_timeout = 0 去掉注释
nginx的配置:
原样:#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
# }
改为:
fastcgi_pass 192.168.2.22:9000;
fastcgi_param CRIPT_FILENAME $document_root$fastcgi_script_name;
总结:listen_address 192.168.2.22:9000; | 127.0.0.1:9000
allow_clients 192.168.2.22; | 127.0.0.1
fastcgi_pass 192.168.2.22:9000; | 127.0.0.1:9000
这三个参数的值必须保持相同
本文出自 “常用文档” 博客,转载请与作者联系!
nginx和FastCGI整合