【Nginx基础】缓存服务proxy(3)

1 fastcgi_cache简介

说起fastcgi不得不提cgi,cgi全称是“通用网关接口”(Common Gateway Interface),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具,其程序一般运行在网络服务器上。 CGI可以用任何一种语言编写,只要这种语言具有标准输入、输出和环境变量。如php,perl,tcl等。摘自百度百科。

那fastcgi意思就是比cgi执行速度要快速。主要快在从启动开始,就一直会有一个常驻的进程一直等待外部的请求,不用每次有请求就fork一个进程处理请求。当然,速度快了,占用的内存就会高了,因为不论有没有客人,总要有人在门口迎宾。


2 设置fastcgi_cache缓存

#设定一个负载均衡
upstream slbserver_cache {
server 127.0.0.1:9000 weight=1 max_fails=2 fail_timeout=2;
}
#设定缓存地址,缓存比例以及缓存名称,缓存大小,缓存时间
fastcgi_cache_path /webroot/blog_cache/ levels=1:2 keys_zone=pp_blog:10m max_size=1g inactive=60m use_temp_path=off;
server {
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /webroot/www;
location ^/(static|Uploads) {
expires 30d;
}
#/admin 相关请求不进行缓存
if ($request_uri ~ ^/admin){
set $nocache 1;
}
location ~ .*\.(php|php5)?$
{
fastcgi_temp_path /var/cache_temp;
fastcgi_cache pp_blog;
fastcgi_cache_key $scheme$request_method$host$request_uri$is_args$args;
add_header X-Cache-Source $upstream_cache_status;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#200请求缓存60分钟
fastcgi_cache_valid 200 60m;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
#设定不缓存的内容
fastcgi_no_cache $nocache $arg_nocache $arg_comment;
include fastcgi_params;
}
}


相关推荐

  • 生成图片

    from PIL import Image, ImageColor, ImageDraw, ImageFont, ImageFilterdef create_image_with_text(size, color, text, font_path, font_size, text_color, shadow_color, output_path): """ Create a new image of specified size and color with centered text that has a border and shadow. :param size: A tuple con

  • 获取指定目录下的所有图片信息

    1 获取指定目录下的所有图片信息// 获取指定目录下的所有图片信息 public function getImagesInfo($directory) { $images = []; // 创建递归目录迭代器 $iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY ); // 遍历目录中的每个文件 foreach (

  • Thinkphp各版本的PHP要求

    ThinkPHP 8.0:运行环境要求PHP8.0+,兼容PHP8.3ThinkPHP 6.1:运行环境要求PHP7.2+,兼容PHP8.1ThinkPHP 6.0:运行环境要求PHP7.2+,兼容PHP8.1ThinkPHP 5.1:运行环境要求PHP5.6+,兼容PHP8.0ThinkPHP 5.0:运行环境要求PHP5.4+,兼容PHP7.3