Nginx的ngx_http_fastcgi_module模块

ngx_http_fastcgi_module模块:

这个模块允许发送请求给fastcgi服务

1、fastcgi_pass address;

将请求发送给address,address为fastcgi server的地址;

2、fastcgi_index name;

fastcgi默认的主页资源;

3、fastcgi_param parameter value [if_not_empty];

设置应该传递给FASCGI服务器的参数。该值可以包含文本、变量以及它们的组合。

配置示例1:

前提:配置好fpm server
        location ~ \.php$ {
            root           /var/www/html;
            fastcgi_pass   127.0.0.1:9000;##fpm在本机
            fastcgi_index  index.php; ##起始页为index.php
            fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name; ##请求的php文件的目录,这里是在/var/www/html/目录下存放php文件。
            include        fastcgi_params; ##传递给fpm server的参数。
        }

4、fastcgi_cache_path

定义fastcgi的缓存;缓存位置为磁盘上的文件系统,由path所指定路径来定义;
格式: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];

  • levels=levels:缓存目录的层级数量,以及每一级的目录数量;
  • 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 服务器将在发送响应后关闭连接。但是,当这个指令设置为ON值时,Nginx将指示fastcgi server保持连接打开。

示例:

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2:1 keys_zone=fcgi:20m inactive=120s;
    server {
        listen       80;
        server_name  localhost;
        root   /var/www/html;
        location / {
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
            include        fastcgi_params;
            fastcgi_cache fcgi;
            fastcgi_cache_key $request_uri;
            fastcgi_cache_valid 200 302 10m;
            fastcgi_cache_valid 301 1h;
            fastcgi_cache_valid any 1m; 
            fastcgi_keep_conn on;
        }
    }
}

访问一次192.168.253.128(nginx服务器)
这里写图片描述

然后我们看缓存目录是否生成了缓存的文件

这里写图片描述

猜你喜欢

转载自blog.csdn.net/L835311324/article/details/82592167
今日推荐