Nginx之ngx_http_fastcgi_module模塊詳解

一、ngx_http_fastcgi_module模塊:

      nginx支持FastCGI模式

      CGI:Common GateWay Interface 公共網管接口,可以理解其為HTTP服務器與其他主機上運行的程序進行通信的接口。

      CGI適合于少量動態請求的場景,一旦遇到大量動態請求時就不能夠高效處理了,而且處理這些請求會消耗大量系統資源,為解決這一問題FastCGI就出現了。

     HTTP模塊默認包含至此FastCGI模式的支持

二、模塊的常見指令

    1、fastcgi_pass address;

        addressfastcgi server的地址; location, if in location

    2、fastcgi_index name;

         fastcgi默認的主頁資源;

    3、fastcgi_param parameter value [if_not_empty];

        設置一個參數給后端的FastCGI服務器,值可以包括文本、變量或它們的組合

   4、fastcgi_cache_path path [levels=levels] [use_temp_path=on|off] keys_zone=name:size [inactive=time] [max_size=size]…

       定義fastcgi的緩存;緩存位置為磁盤上的文件系統,由path所指定路徑來定義;

      levels=levels:緩存目錄的層級數量,以及每一級的目錄數量;levels=ONE:TWO:THREE

      keys_zone=name:size:k/v映射的內存空間的名稱及大小

      inactive=time:非活動時長

      max_size=size:磁盤上用于緩存數據的緩存空間上限

   5、fastcgi_cache zone | off;

      調用指定的緩存空間來緩存數據;http, server, location

   6、fastcgi_cache_key string;

       定義用作緩存項的key的字符串;

   7、fastcgi_cache_methods GET | HEAD | POST …;

       為哪些請求方法使用緩存;

   8、fastcgi_cache_min_uses number;

        緩存空間中的緩存項在inactive定義的非活動時間內至少要被訪問到此處所指定的次數方可被認作活動項;

   9、fastcgi_cache_valid [code …] time;

        不同的響應碼各自的緩存時長;

   10、fastcgi_keep_conn on | off;(發起請求時保持鏈接)

三、利用fastcgi 實現lnmp(phpadmin包實現)

   要求:動態資源單獨一個服務器(192.168.109.128

            靜態資源單獨一個服務器(192.168.109.130

            反向代理服務器 192.168.109.129

            數據庫服務器(192.168.109.131 

   拓撲:

    Nginx之ngx_http_fastcgi_module模塊詳解

一、數據庫配置(192.168109、131

    1、安裝數據庫mariadb-server

yum install mariadb-server

    2、修改配置文件

        vim /etc/my.cnf.d/server.cnf

       Nginx之ngx_http_fastcgi_module模塊詳解

   3、啟動服務

              Nginx之ngx_http_fastcgi_module模塊詳解

          4、創建數據庫(wordpress)并授權用戶zq

             Nginx之ngx_http_fastcgi_module模塊詳解 

二、靜態資源配置

1、安裝包

   Yum install nginx

2、定義虛擬主機

          Nginx之ngx_http_fastcgi_module模塊詳解       

3.創建URL目錄

        并在此目錄下下載phpadmin包解壓

 Mkdir /data/www

 Cd /data/www

 下載包解壓

  tar xf phpMyAdmin-4.0.10.20-all-languages.tar.gz

  創建鏈接文件

  ln -sv phpMyAdmin-4.0.10.20-all-languages pma

      4、啟動服務

         Systemctl start nginx.sevice

三、fastcgi服務器動態資源

      1、安裝包

         yum install php-fpm  php-mysql php-mbstring php-mcrypt

      2、修改php-fpm配置文件

        vim /etc/php-fpm.d/www.conf

        Nginx之ngx_http_fastcgi_module模塊詳解

    3、創建目錄/data/www(使其與反向代理服務器fastcgi_param SCRIPT_FILENAME /data/www/$fastcgi_script_name對應)

        并在此目錄中存放動態資源

        mkdir -pv /data/www

        cd /data/www

     下載包phpadmin包并解壓在此目錄,然后創建鏈接文件pma

       Nginx之ngx_http_fastcgi_module模塊詳解

     4、編輯phpadmin配置文件

          cd /data/www/pma

          創建配置文件

          cp config.sample.inc.php  config.inc.php

          修改配置文件(將數據庫位置指向數據庫服務器)

         vim config.inc.php

       Nginx之ngx_http_fastcgi_module模塊詳解

    5、啟動服務

systemctl start php-fpm

Nginx之ngx_http_fastcgi_module模塊詳解   

四、配置反向代理服務器

1、安裝包

    Yum install nginx

2、定義代理緩存路徑和fastcgi緩存路徑

   vim nginx.conf

   Nginx之ngx_http_fastcgi_module模塊詳解

  3、配置虛擬主機

        Vim  /etc/nginx/conf.d/vir.conf 

        定義靜態資源位置

        Nginx之ngx_http_fastcgi_module模塊詳解

       定義動態資源位置

        Nginx之ngx_http_fastcgi_module模塊詳解

   4、啟動服務

       Systemctl start nginx.service

五、測試

      輸入www.zl.com/pma/index.php

       Nginx之ngx_http_fastcgi_module模塊詳解

六、開啟ping測試status

   1、修改fpm服務器配置文件

     vim /etc/php-fpm.d/www.conf

      Nginx之ngx_http_fastcgi_module模塊詳解

  Systemctl restart php-fom    

   2、配置代理服務器

     Nginx之ngx_http_fastcgi_module模塊詳解

   systemctl restart nginx.service

   3、測試

    ping測試頁面為pong

    Nginx之ngx_http_fastcgi_module模塊詳解

    狀態頁面

    Nginx之ngx_http_fastcgi_module模塊詳解

 

 

 

 

原創文章,作者:zq,如若轉載,請注明出處:http://www.www58058.com/78498

(1)
zqzq
上一篇 2017-06-25 14:59
下一篇 2017-06-25 18:50

相關推薦

  • iptables歸納總結

    先簡單介紹下iptables IPTABLES的幾點概念  1、容器:包含或者說屬于的關系  2、Netfilter/iptables是表的容器,iptables包含的各個表 (filter,NAT,MANGLE,RAW)  3、iptables的表tables又是鏈的容器 鏈chains:INPUT,OUTPUT,FORWAR…

    Linux干貨 2017-05-02
  • N25第八周學習總結_sed命令詳解

    sed使用詳解 大綱: 1、    sed是什么 2、    為什么要使用sed 3、    sed使用方法 4、    sed詳解   正題: 1、    sed是什么 sed全名Stream Ed…

    2017-02-26
  • 9 grep & egrep & 正則表達式

    grep grep = Global search REgular expression and Print out the line 語法及用途 grep [OPTIONS] PATTERN [FILE…] 根據用戶指定的“…

    Linux干貨 2016-08-10
  • N25 第二周作業

    一.Linux上常用的文件管理類命令及用法示例     1.cp復制命令,具體有兩個,一為單源復制,一種為多源復制。      常用選項         -i :交互式復制,覆蓋之前提醒用戶確認。       …

    Linux干貨 2016-12-12
  • yum初步入門

                             yum工具是為提高RPM軟件安裝性而開發的一種軟件包管理器,是由pyt…

    Linux干貨 2015-04-01
欧美性久久久久