ngx_http_fastcgi_module模塊

該模塊轉發請求到FastCGI服務器,不支持php模塊方式

1、fastcgi_pass address;(Context:location, if in location)

    address爲後端的fastcgi server的地址

2、fastcgi_index name;

    fastcgi默認的主頁資源

    示例:

        fastcgi_index index.php;

3、fastcgi_param parameter value [if_not_empty];

    設置傳遞給 FastCGI服務器的參數值,可以是文本,變量或組合

     示例1:

        1)在後端服務器先配置fpm server和mariadb-server

        2)在前端nginx服務上做以下配置:

location ~* \.php$ {
    fastcgi_pass 後端fpm服務器IP:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME
    /usr/share/nginx/html$fastcgi_script_name;
    include fastcgi_params;
    …
}

    示例2:通過/pm_status和/ping來獲取fpm server狀態信息

location ~* ^/(pm_status|ping)$ {
    include fastcgi_params;
    fastcgi_pass 後端fpm服務器IP :9000;
    fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}

4、fastcgi_cache_path path [levels=levels][use_temp_path=on|off]keys_zone=name:size [inactive=time] [max_size=size] [manager_files=number] [manager_sleep=time] [manager_threshold=time][loader_files=number] [loader_sleep=time][loader_threshold=time] [purger=on|off] [purger_files=number] [purger_sleep=time] [purger_threshold=time];

    定義fastcgi的緩存;

  • path 緩存位置爲磁盤上的文件系統

  • max_size=size 磁盤path路徑中用於緩存數據的緩存空間上限

  • levels=levels:緩存目錄的層級數量,以及每一級的目錄數量

  • levels=ONE:TWO:THREE

    示例:

        leves=1:2:2

        keys_zone=name:size

        k/v映射的內存空間的名稱及大小

        inactive=time 非活動時長

5、fastcgi_cache zone | off;(Context:http, server, location)

    調用指定的緩存空間來緩存數據

6、fastcgi_cache_key string;

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

    示例:

        fastcgi_cache_key $request_rui;

7、fastcgi_cache_methods GET | HEAD | POST ...;

    爲請求方法使用緩存

8、fastcgi_cache_min_uses number;

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

9、fastcgi_keep_conn on | off;

    收到後端服務器響應後,fastcgi服務器是否關閉連接,建議啓用長連接

10、fastcgi_cache_valid [code ...] time;

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

    示例:

http {
    fastcgi_cache_path /var/cache/nginx/fcgi_cache
    levels=1:2:1 keys_zone=fcgicache:20m inactive=120s;
    ...
    server {
        location ~* \.php$ {
        ...
        fastcgi_cache fcgicache;
        fastcgi_cache_key $request_uri;
        fastcgi_cache_valid 200 302 10m;
        fastcgi_cache_valid 301 1h;
        fastcgi_cache_valid any 1m;
        ...
        }
    }
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章