Cc'ing the openresty mailing list.
---------- Forwarded message ----------
From: chaepil lim <chaeplin@gmail.com>
Date: Tue, Apr 10, 2012 at 6:50 AM
Subject: Re: Using ngx_srcache for responses exceeding 1MB (Was Re:
Thank You Your for Your Program)
To: agentzh <age...@gmail.com>
Hello.
I am not using redis yet. Still waiting srcache's 304 feature.
As you know, I have used the following config
---------
set_by_lua $skip '
if ngx.var.cookie_ologin == "1" then
return 1
end
if ngx.var.request_method == "POST" then
return 1
end
return 0
';
srcache_fetch_skip $skip;
srcache_store_skip $skip;
set $key $uri$args$request_method;
srcache_fetch GET /memc60 $key;
srcache_store PUT /memc60 $key;
header_filter_by_lua '
if (ngx.header["X-Authed-Site"] == "ONOFFMIX") then
ngx.var.skip = 1
end
';
--------
After read your
ebook/http://agentzh.org/misc/nginx/agentzh-nginx-tutorials-enuk.html,
I have found header_filter_by_lua and srcache_store_skip have same
phase output-header-filter.
If following condition met, response is stored which should not.
1) memcched has no value/object for the key
2) if X-Authed-Site is equal to ONOFFMIX
So I use map. Works fine.
--------------
map $cookie_ologin $skip_cookie {
default 0;
1 1;
}
map $upstream_http_X_Authed_Site $skip_header {
default 0;
ONOFFMIX 1;
}
srcache_fetch_skip $skip_cookie;
srcache_store_skip $skip_header;
srcache_store_hide_header X-Authed-Site;
set $key $uri$args$request_method;
srcache_fetch GET /memc60 $key;
srcache_store PUT /memc60 $key;
--------------
Thank you again.
2012. 3. 22., 오후 6:14, agentzh 작성:
On Wed, Mar 21, 2012 at 5:32 PM, agentzh <age...@gmail.com> wrote:
>
> I'll work out a working ngx_srcache + ngx_redis/ngx_redis2 example for
> you to try in the next few days or so :)
>
Here is a working example that has been tested carefully on my side:
location /foo {
default_type text/css;
set $key $uri;
set_escape_uri $escaped_key $key;
srcache_fetch GET /redis $key;
srcache_store POST /redis2 key=$escaped_key&exptime=120;
echo_duplicate 2097152 a;
}
location = /redis {
internal;
set $redis_key $args;
redis_pass 127.0.0.1:6379;
}
location = /redis2 {
internal;
set_unescape_uri $exptime $arg_exptime;
set_unescape_uri $key $arg_key;
redis2_query set $key $echo_request_body;
redis2_query expire $key $exptime;
redis2_pass 127.0.0.1:6379;
}
This example uses ngx_echo's echo_duplicate directive to emit 2MB's
data (2097152 a's).
This example makes use of the $echo_request_body variable provided by
the ngx_echo module. Note that you need the latest version of
ngx_echo, v0.38rc2:
https://github.com/agentzh/echo-nginx-module/tags
Earlier versions of ngx_echo will not work reliably.
Also, you need both the ngx_redis and ngx_redis2 modules here:
http://wiki.nginx.org/HttpRedisModule
http://wiki.nginx.org/HttpRedis2Module
Sergey A. Osokin's ngx_redis module's current latest version, 0.3.5,
has a bug that could cause problems. A patch is provided here:
https://groups.google.com/group/openresty/browse_thread/thread/b5ddf1b24d3c9677
Finally, the Nginx core also has a bug that could prevent ngx_redis2's
pipelining support from working properly in certain extreme
conditions. And the following patch fixes this:
http://mailman.nginx.org/pipermail/nginx-devel/2012-March/002040.html
Note that, if you're using the ngx_openresty 1.0.11.27 bundle or
later, then you only need to prepare Sergey A. Osokin's ngx_redis
module and the patch mentioned above, because other patches and
components are already applied in the bundle properly but the
ngx_redis module is not included in the bundle yet.
If you have any other issues, please let us know :)
Enjoy!
-agentzh