码迷,mamicode.com
首页 > Web开发 > 详细

ngx_http_fastcgi_module模块

时间:2018-03-30 10:50:37      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:Linux   Nginx   

该模块转发请求到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;
        ...
        }
    }
}



ngx_http_fastcgi_module模块

标签:Linux   Nginx   

原文地址:http://blog.51cto.com/13520924/2092793

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!