erlchina 发表于 2018-12-18 10:42:47

nginx + PHP (FastCGI) 高性能服务器部署

  LNAMP (linux + nginx + mysql + php)

  

        CGI 全称是“公共网关接口”(common gateway interface),是WEB 服务器与其它服务器进行“交谈”的工具,它的程序运行在网络服务器上。它可以用任何一种语言编写,只要这种语言具有标准输入,输出和环境变量。如 php, perl, tcl 等。

  

        FastCGI:WEB 服务器与处理程序之间通信的一种协议 (app server 和 web server 之间的通信协议),是CGI 的改进方案。CGI 反复加载成为其性能低下的主要原因,若 CGI 程序保持在内存中并接受 FastCGI 进程管理高度,则可以提供良好的性能,伸缩性,Fail-Over 特性等。
        FastCGI是常驻型的 CGI,它可以一直运行,将CGI 解释器进程保持在内存中,以此获得较高的性能。
         FastCGI 是一个协议,php-fpm 实现了这个协议,php-fpm 的fastcgi 协议需要有进程池,php-fpm 实现的 fastcgi 进程叫 php-cgi, 所以 php-fpm 也是他自身的 fastcgi 或 php-cgi 进程管理器。

  

  工作原理图:
  

  

  http://s3.运维网.com/wyfs02/M02/72/FD/wKioL1XxXi2DI8tzAACImfsluWg398.jpg
  

  

  Nginx + FastCGI 安装配置:
  

  1.部署 mysql主从 服务器(详细安装见MySQL 主从复制)
  

  2.安装 nginx 服务 (详情请参考如何搭建 Nginx 网站服务器)
  

  3.下载编译安装 PHP
      cd/data

      wgethttp://museum.php.net/php5/php-5.3.10.tar.gz
      yum -y installgdcurlcurl-devellibjpeglibjpeg-devellibpnglibpng-develfreetypefreetype-devellibxml2libxml2-develmysqlmysql-devel

  

      tar zxf php-5.3.10 .tar.gz ; cdphp-5.3.10
      ./configure--prefix=/usr/local/php5
                          --enable-fpm --enable-debug
                          --with-gd--with-jpeg-dir
                          --with-png-dir --with-freetype-dir
                          --enable-mbstring--with-curl
                         --with-mysql=mysqlnd
                        --with-mysqli=mysqlnd
                        --with-pdo-mysql=mysqlnd
  

  

      make && makeinstall

  

      cpphp.ini-development    /usr/local/php5/lib/php.ini

      cp /usr/local/php5/etc/php-fpm.conf.default    /usr/local/php5/etc/php-fpm.conf    /usr/local/php/sbin/php-fpm

      cp    sapi/fpm/init.d.php-fpm      /etc/init.d/php-fpm

  

  2.Nginx 文件设置:
  

  
server {
include port.conf;
server_name www.jfedu.netjfedu.net;
location / {
index index.htmlindex.php;
root/usr/local/nginx/html;
}
location~ \.php$ {
            root         html;
         fastcgi_pass127.0.0.1:9000;
            fastcgi_indexindex.php;
         fastcgi_param SCRIPT_FILENAME html$fastcgi_script_name;
            include      fastcgi_params;
      }
}
  
测试 Nginx + PHP 整合结果

  

http://s3.运维网.com/wyfs02/M00/73/00/wKiom1XxYHKSn4etAAIwhwoxVVY295.jpg
  

  

  

  

  

  




页: [1]
查看完整版本: nginx + PHP (FastCGI) 高性能服务器部署