亲自测试发现,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输出的内容的更多相关文章

  1. 【摘自张宴的"实战:Nginx"】使用nginx的proxy_cache模块替代squid,缓存静态文件

    #user nobody;worker_processes 1; error_log logs/static_source.error.log;#error_log logs/error.log no ...

  2. 【摘自张宴的"实战:Nginx"】nginx模块开发

    Nginx的模块不能够像Apache那样动态的加载,所以模块都要预先编译进Nginx的二进制可执行文件中. Nginx的模块有三种角色: 1. Handler(处理模块)     用于处理Http请求 ...

  3. 【摘自张宴的"实战:Nginx"】nginx配置

    user nobody;worker_processes 2; #error_log logs/error.log;error_log logs/error.log notice;#error_log ...

  4. 【摘自张宴的"实战:Nginx"】http auth baseic模块(打开页面需要密码验证)

    location /admin { auth_basic "kingsoft"; auth_basic_user_file httppasswd;      #密码文件的路径  默 ...

  5. 【摘自张宴的"实战:Nginx"】try_files指令

    语法:try_files param1 [param2...paramN] fallback 默认值:none 使用环境: location 该指令用于告诉nginx测试每个文件是否存在,并且使用首先 ...

  6. 【摘自张宴的"实战:Nginx"】Nginx的server指令

    server 语法:server name[parameters] 默认值:none 使用环境:upstream 该指令用于指定后端服务器的名称和参数.服务器的名称可以是一个域名.一个IP地址.端口号 ...

  7. php在Nginx环境下进行刷新缓存立即输出,实现常驻进程轮询。

    以下面这段代码并不会逐个输出,而是当浏览器筹够一定字节数进行统一输出,结果显而易见,10秒后一次性输出所有内容 for($i=0;$i<10;$i++){ echo $i.'</br> ...

  8. nginx实现负载均衡、缓存功能实战

    nginx实现负载均衡.缓存功能实战 什么是正向代理?应用场景:翻墙 什么是反向代理?例如:haproxy和nginx   Nginx实现反向代理 nginx代理基于是ngx_http_proxy_m ...

  9. [Nginx]实战Nginx:Nginx服务器的安装与配置

    ----------------------------------------------------------------------------------------------- Ngin ...

随机推荐

  1. 简单的说一下:tarits技法就是一种模板元编程,起可以将本来处于运行期的事拉到编译期来做,增加了运行效率。 看以非模板元编程的例子,就是前面的那个例子:

    void adance(std::list<int>::iterator& iter, int d) { if(typeid(std::iterator_traits<std ...

  2. New Concept English three (58)

    30w/m 76 errors The old lady was glad to be back at the block of flats where she lived. Her shopping ...

  3. 关于/usr/bin/ld: cannot find -lcrypto 的错误

    Linux下 build code 时,要做 -lssl, -lcrypto 的链接,出现类似下面的错误: /usr/bin/ld: cannot find -lcrypto /usr/bin/ld: ...

  4. HDU4416Good Article Good sentence(后缀自动机)

    Problem Description In middle school, teachers used to encourage us to pick up pretty sentences so t ...

  5. New Year and Buggy Bot

    Bob programmed a robot to navigate through a 2d maze. The maze has some obstacles. Empty cells are d ...

  6. h5废弃的标签和属性及新增的标签和属性

    一.废弃的标签和属性 1.表现性元素 a) basefont b) big c) center d) font e) strike f) tt 2.框架类元素 a) frame b) frameset ...

  7. C++对C语言的拓展(2)—— inline内联函数

    C语言中有宏函数的概念.宏函数的特点是内嵌到调用代码中去,避免了函数调用 的开销.但是由于宏函数的处理发生在预处理阶段,缺失了语法检测和有可能带来的语意差错. 1.内联函数基本概念 C++提供了 in ...

  8. 市场上 MLCC 226 电容现象

    市场上 MLCC 226 电容现象 三星 X7R 1206 没有 16V 也有人在卖. Y5V 当 X7R 卖. X5R 当 X7R 卖. 薄电容当厚的电容卖.

  9. Raid信息丢失数据恢复及oracle数据库恢复验证方案

    早些时候,有个客户14块盘的磁盘阵列出现故障,需要恢复的数据是oracle数据库,客户在寻求数据恢复技术支持,要求我提供详细的数据恢复方案,以下是提供给客户的详细数据恢复解决方案,本方案包含Raid数 ...

  10. Win7服务器搭建实例教程:教你Win7如何搭建Web服务器【转载】

    原文地址:http://www.pc841.com/article/20140607-30534.html 局域网Web服务器的主要功能是实现资源共享,同时借助于局域网服务器访问页面可有效的实现信息的 ...