Hello!
On Fri, Nov 23, 2012 at 10:09 AM, 郝巍 wrote:
> 最近我使用openresty中的srcache做一些静态页面的缓存。
>
> 按照srcache模块介绍的配置方法,进行了如下修改:
>
> upstream redis_backend {
> server 192.168.1.102:6379;
> keepalive 512;
> }
>
>
> # get from Redis
> location = /redisget {
> internal;
> set $key $arg_key;
> redis2_query get $key;
> redis2_pass redis_backend;
> }
>
你的 location /redisget 应当使用 ngx_redis 模块,而非 ngx_redis2 模块,因为 ngx_redis2
总是返回经过 redis 协议编码后的数据(也就是 redis 服务器返回的原始数据)。而 srcache_fetch
期望子请求返回(经过解码后的)原始数据。
细节可以参见ngx_srcache 文档中的 "Caching with Redis" 一节:
http://wiki.nginx.org/HttpSRCacheModule#Caching_with_Redis
>
> # set to Redis
> location = /redisput {
>
> internal;
> set_unescape_uri $key $arg_key;
> redis2_query set $key $echo_request_body;
> redis2_pass redis_backend;
> }
>
>
> location / {
> set $key $uri;
> set_escape_uri $escaped_key $key;
>
> srcache_fetch GET /redisget key=$key;
> srcache_store PUT /redisput key=$escaped_key;
>
> root /opt/www/gw;
> index index.html;
>
> }
>
> 那么访问静态页面时,"/redisput" 段落正常,不过 "/redisget" 段落出现问
> 题,debug信息如下:
>
> srcache_fetch: cache sent invalid status line while sending to client,
> client: 192.168.1.102, server: www.catchtech.tst, request:
> "GET /products.html HTTP/1.1", subrequest: "/redisget", upstream:
> "redis2://192.168.1.102:6379", host: "www.catchtech.tst", referrer:
> "http://www.catchtech.tst/index.html"
>
这个错误信息清楚地指示出 srcache_fetch 看到你的 /redisget 子请求返回的数据不是它所期望的。而这正是我上面指出的使用
ngx_redis2 模块的问题。你这里应当换用 ngx_redis 模块。(不过 /redisput 还是应当使用
ngx_redis2.)
>
> 如"/redisget" 段落改为:
>
> location = /redisget {
> internal;
> set $key $arg_key;
> set $redis_key $key;
> redis_pass redis_backend;
> }
> 则正常:
>
> 2012/11/24 01:43:20 [debug] 3223#0: *443 srcache_fetch: subrequest
> returned status 200
> 2012/11/24 01:43:20 [debug] 3223#0: *443 srcache_fetch decides to send
> the response in cache
> 2012/11/24 01:43:20 [debug] 3223#0: *443 srcache_fetch status line done
> 2012/11/24 01:43:20 [debug] 3223#0: *443 srcache_fetch header:
> "Content-Type: text/html"
> 2012/11/24 01:43:20 [debug] 3223#0: *443 srcache_fetch header:
> "Last-Modified: Fri, 23 Nov 2012 09:23:44 GMT"
> 2012/11/24 01:43:20 [debug] 3223#0: *443 srcache_fetch header:
> "X-SRCache-Allow-Ranges: 1"
> 2012/11/24 01:43:20 [debug] 3223#0: *443 srcache_fetch header done
>
> 我的疑问是:是不是 HttpRedis2Module 还不能和 srcache一起使用?
>
是的,srcache_fetch 需要使用 ngx_redis 模块,而 srcache_store 需要使用 ngx_redis2
模块。这两个模块的功能并不相同。
同时抄送给 openresty
中文邮件列表,希望你在那里和我们交流这样的问题:https://groups.google.com/group/openresty
谢谢合作!
Best regards,
-agentzh