【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;
}
}


相关推荐

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

    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

  • Thinkphp5.1路径常量

    1 配置文件位置根目录/config/template.php2 配置文件内容<?php// +----------------------------------------------------------------------// | ThinkPHP [ WE CAN DO IT JUST THINK ]// +----------------------------------------------------------------------// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reser

  • Thinkphp5.0路径常量

    1 配置文件位置根目录/application/模块名/config.php2 配置文件内容<?php//配置文件return [ // 后台视图输出字符串内容替换 'view_replace_str' => [ '__PUBLIC__' => '/', '__STATIC__' => '/static', '__CONSOLE__' => '/static/console', '__CONSOLE_CSS__' => '/static/console/css', '__CONSOLE_IMAGES__' => '/static/console/ima

  • wp站点防止别人进行DDOS攻击

    1 简介wp站点防止别人进行DDOS攻击。2 配置位置位置:根目录/wp-config.php3 配置内容在【根目录/wp-config.php】文件的开头添加如下代码:if(strpos($_SERVER['REQUEST_URI'], 'xmlrpc.php') !== false){ $protocol = $_SERVER['SERVER_PROTOCOL'] ?? ''; if(!in_array($protocol, ['HTTP/1.1', 'HTTP/2', 'HTTP/2.0', 'HTTP/3'], true)){ $protocol = 'HTTP/1.0'; } hea

  • 只读属性

    1 只读属性简介只读属性的声明方式类似于普通属性,但需要使用 readonly 关键字。2 只读属性例子class Point { public readonly float $x; public readonly float $y; public function __construct(float $x, float $y) { $this->x = $x; $this->y = $y; }}$point = new Point(3.5, 2.8);echo $point->x; // 输出: 3.5echo $point->y; // 输出: 2.8// 下面的尝