【摘自张宴的"实战:Nginx"】使用nginx的fastcgi_cache缓存php输出的内容
亲自测试发现,fastcgi_cache虽然可以缓存生成的php输出的文件,但是有个弊端,在缓存的失效时间之内,你继续访问这个地址,输出的内容没有发生变化,即使数据库新增了数据或者删除了数据,所以不适合来做即时的数据查询;
#user nobody;
worker_processes 1;
error_log logs/static_source.error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/static_source.access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
#*************************************************************************
#注 fastcgi_temp_path, fastcgi_cache_path指定的路径必须在一个分区
fastcgi_temp_path /data/fastcgi_temp_path;
#设置web缓存区的名字为cache_one ,内存缓存空间大小为200M, 自动清除超过1天美意被访问的缓存数据,磁盘空间大小为30GB
fastcgi_cache_path /data/fastcgi_cache_path levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;
root /data/www/static;
server {
listen 80;
server_name www.test.com;
charset utf-8;
access_log logs/test.access.log main;
#location /
#{
# proxy_set_header Host $host;
# proxy_set_header X-Forwarded-For $remote_addr;
# proxy_pass http://my_server_pool;
#
#}
location ~ .*\.(php)?$
{
fastcgi_cache cache_one;
#对不同状态码缓存设置不同的缓存时间
fastcgi_cache_valid 200 10m
fastcgi_cache_valid 301 302 1h;
fastcgi_cache_valid any 1m;
fastcgi_cache_key 127.0.0.1:9000$request_uri;
#fastcgi服务器
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
访问http://192.168.66.138/a.php会在目录/data/fastcgi_cache_path生成a.php输出的缓存的内容,php输出的内容为
testhelojack (10) tome (88)
生成的缓存的文件b7629eb874ec26fe28dd33e6183f9b5c(nginx根据配置的Key,md5生成的文件名)内容为:
1 ^C^@^@^@D^LHWÿÿÿÿ4þGWÿkó3^@^@<9b>^@Ø^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^ ^@^@^@^@^@
2 KEY: 127.0.0.1:9000/a.php
3 ^A^F^@^A^@Q^G^@X-Powered-By: PHP/5.5.30^M
4 Content-type: text/html^M
5 ^M
6 testhelojack (10)
7 tome (88)
【摘自张宴的"实战:Nginx"】使用nginx的fastcgi_cache缓存php输出的内容的更多相关文章
- 【摘自张宴的"实战:Nginx"】使用nginx的proxy_cache模块替代squid,缓存静态文件
#user nobody;worker_processes 1; error_log logs/static_source.error.log;#error_log logs/error.log no ...
- 【摘自张宴的"实战:Nginx"】nginx模块开发
Nginx的模块不能够像Apache那样动态的加载,所以模块都要预先编译进Nginx的二进制可执行文件中. Nginx的模块有三种角色: 1. Handler(处理模块) 用于处理Http请求 ...
- 【摘自张宴的"实战:Nginx"】nginx配置
user nobody;worker_processes 2; #error_log logs/error.log;error_log logs/error.log notice;#error_log ...
- 【摘自张宴的"实战:Nginx"】http auth baseic模块(打开页面需要密码验证)
location /admin { auth_basic "kingsoft"; auth_basic_user_file httppasswd; #密码文件的路径 默 ...
- 【摘自张宴的"实战:Nginx"】try_files指令
语法:try_files param1 [param2...paramN] fallback 默认值:none 使用环境: location 该指令用于告诉nginx测试每个文件是否存在,并且使用首先 ...
- 【摘自张宴的"实战:Nginx"】Nginx的server指令
server 语法:server name[parameters] 默认值:none 使用环境:upstream 该指令用于指定后端服务器的名称和参数.服务器的名称可以是一个域名.一个IP地址.端口号 ...
- php在Nginx环境下进行刷新缓存立即输出,实现常驻进程轮询。
以下面这段代码并不会逐个输出,而是当浏览器筹够一定字节数进行统一输出,结果显而易见,10秒后一次性输出所有内容 for($i=0;$i<10;$i++){ echo $i.'</br> ...
- nginx实现负载均衡、缓存功能实战
nginx实现负载均衡.缓存功能实战 什么是正向代理?应用场景:翻墙 什么是反向代理?例如:haproxy和nginx Nginx实现反向代理 nginx代理基于是ngx_http_proxy_m ...
- [Nginx]实战Nginx:Nginx服务器的安装与配置
----------------------------------------------------------------------------------------------- Ngin ...
随机推荐
- linux下配置cvs服务器以及cvs常用命令
.查看系统是否安装有cvs #cat /etc/services | grep cvspserver 看看是否有: cvspserver /tcp #CVS client/server operati ...
- Mayor's posters (线段树加离散化)
个人心得:线段树也有了一定的掌握,线段树对于区间问题的高效性还是挺好的,不过当区间过大时就需要离散化了,一直不了解离散化是什么鬼,后面去看了下 离散化,把无限空间中有限的个体映射到有限的空间中去,以此 ...
- windows10环境下运行Debug
1. 什么是Debug? Debug是DOS.Windows都提供的实模式(8086方式)程序的调试工具. 使用它,可以查看CPU各种寄存器中的内容.内存的情况和在机器码级别跟踪程序的运行. 2. 常 ...
- mysql之 mysql 5.6不停机主从搭建(一主一从基于日志点复制)
环境说明:版本 version 5.6.25-log 主库ip: 10.219.24.25从库ip:10.219.24.22os 版本: centos 6.7已安装热备软件:xtrabackup 防火 ...
- angular +H5 上传图片 与预览图片
//index.html <form class="form-horizontal"> <div class="panel panel-default& ...
- bzoj 1997 [Hnoi2010]Planar——2-SAT+平面图的一个定理
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1997 平面图的一个定理:若边数大于(3*点数-6),则该图不是平面图. 然后就可以2-SAT ...
- jQuery中 :first、:first-child 和 :first-of-type 之间的不同
<!DOCTYPE html><html><head><meta charset="utf-8"><script src=&q ...
- SQLite连接C#笔记
不得不吐槽,实在是太坑了.以下几点一定要注意: 要下载两个东西,都要上官网.一个是SQLite for Windows,一个是System.Data.SQLite. 下载下来的DLL里面有个test, ...
- MongoDB 3.4 高可用集群搭建(二)replica set 副本集
转自:http://www.lanceyan.com/tech/mongodb/mongodb_repset1.html 在上一篇文章<MongoDB 3.4 高可用集群搭建(一):主从模式&g ...
- java中内部类的讲解
java中有一个内部类的概念,由于之前一直比较忙,没有单独拿出时间总结一下,今天我就把内部类的相关知识进行一下汇总,如果有不足之处,欢迎批评指正. 1)java内部类的概念. 在一个类的的 ...