【摘自张宴的"实战: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 ...
随机推荐
- AI探索(三)Tensorflow编程模型
Tensorflow编程模型 ....后续完善 import os os.environ[' import numpy as np num_points = data_array = [] for i ...
- L123
My heart, the bird of the wilderness, has found its sky in your eyes. 我的心是旷野的鸟,在你的双眼中找到了天空.His main ...
- Makefile中的路径
使用 $(shell pwd) 可以在Makefile中指定为当前Makefile所在目录的路径
- HIVE-分区表详解以及实例
HIVE中的分区表是什么,我们先看操作,然后再来体会. 创建一个分区表,分区的单位时dt和国家名 hive> create table logs(ts bigint,line string) & ...
- Linux驱动 - SPI驱动 之三 SPI控制器驱动
通过第一篇文章,我们已经知道,整个SPI驱动架构可以分为协议驱动.通用接口层和控制器驱动三大部分.其中,控制器驱动负责最底层的数据收发工作,为了完成数据的收发工作,控制器驱动需要完成以下这些功能:1. ...
- 关于mybatis中基本类型条件判断问题
零:sql动态语句中经常会有根据数据库某个字段状态进行判断的 如:status=0为未激活,status=1为激活的,那搜索未激活时: <if test="model.activeSt ...
- C# winfrom FastReport 变量设计加载
1.源码 DataTable dt5 = new DataTable(); dt5 = SqlHelper.SqlGetDataTable(StrSql, "tbEmpCont") ...
- sql server将字符串转换为 uniqueidentifier 时失败
sql server查询中出现 将字符串转换为 uniqueidentifier 时失败异常 原因为id设置为uniqueidentifier 字段,在where查询时需要做转换cast(id as ...
- Oracle 静默安装 oracle 12c
[oracle@local12cdg app]$ id oracleuid=501(oracle) gid=501(oinstall) groups=501(oinstall),502(dba)[or ...
- wpf数据验证实例及常用方法小结
虽然标题是wpf数据验证,但并不是对IDataErrorInfo.ValidationRule.属性中throw Exception这几种验证方式的介绍: 之前做项目时(例如员工工资管理),根据员工编 ...