9
9
This module is production ready.
10
10
11
11
Version
12
- This document describes srcache-nginx-module v0.22
13
- (<https://github.com/agentzh/srcache-nginx-module/tags>) released on 6
14
- August 2013.
12
+ This document describes srcache-nginx-module v0.23
13
+ (<https://github.com/agentzh/srcache-nginx-module/tags>) released on 27
14
+ October 2013.
15
15
16
16
Synopsis
17
17
upstream my_memcached {
@@ -276,6 +276,63 @@ Description
276
276
(<http://openresty.org/>) 1.0.15.3 bundle or later, then you already
277
277
have everything that you need here in the bundle.
278
278
279
+ Cache Key Preprocessing
280
+ It is often desired to preprocess the cache key to exclude random noises
281
+ that may hurt the cache hit rate. For example, random session IDs in the
282
+ URI arguments are usually desired to get removed.
283
+
284
+ Consider the following URI querystring
285
+
286
+ SID=BC3781C3-2E02-4A11-89CF-34E5CFE8B0EF&UID=44332&L=EN&M=1&H=1&UNC=0&SRC=LK&RT=62
287
+
288
+ we want to remove the "SID" and "UID" arguments from it. It is easy to
289
+ achieve if you use [[HttpLuaModule]] at the same time:
290
+
291
+ location = /t {
292
+ rewrite_by_lua '
293
+ local args = ngx.req.get_uri_args()
294
+ args.SID = nil
295
+ args.UID = nil
296
+ ngx.req.set_uri_args(args)
297
+ ';
298
+
299
+ echo $args;
300
+ }
301
+
302
+ Here we use the echo directive from [[HttpEchoModule]] to dump out the
303
+ final value of $args in the end. You can replace it with your
304
+ [[HttpSRCacheModule]] configurations and upstream configurations instead
305
+ for your case. Let's test this /t interface with curl:
306
+
307
+ $ curl 'localhost:8081/t?RT=62&SID=BC3781C3-2E02-4A11-89CF-34E5CFE8B0EF&UID=44332&L=EN&M=1&H=1&UNC=0&SRC=LK'
308
+ M=1&UNC=0&RT=62&H=1&L=EN&SRC=LK
309
+
310
+ It is worth mentioning that, if you want to retain the order of the URI
311
+ arguments, then you can do string substitutions on the value of $args
312
+ directly, for example,
313
+
314
+ location = /t {
315
+ rewrite_by_lua '
316
+ local args = ngx.var.args
317
+ newargs, n, err = ngx.re.gsub(args, [[\b[SU]ID=[^&]*&?]], "", "jo")
318
+ if n and n > 0 then
319
+ ngx.var.args = newargs
320
+ end
321
+ ';
322
+
323
+ echo $args;
324
+ }
325
+
326
+ Now test it with the original curl command again, we get exactly what we
327
+ would expect:
328
+
329
+ RT=62&L=EN&M=1&H=1&UNC=0&SRC=LK
330
+
331
+ But for caching purposes, it's good to normalize the URI argument order
332
+ so that you can increase the cache hit rate. And the hash table entry
333
+ order used by LuaJIT or Lua can be used to normalize the order as a nice
334
+ side effect.
335
+
279
336
Directives
280
337
srcache_fetch
281
338
syntax: *srcache_fetch <method> <uri> <args>?*
@@ -922,22 +979,23 @@ Installation
922
979
Alternatively, you can build Nginx with this module all by yourself:
923
980
924
981
* Grab the nginx source code from nginx.org (<http://nginx.org>), for
925
- example, the version 1.4.1 (see Nginx Compatibility),
982
+ example, the version 1.4.3 (see Nginx Compatibility),
926
983
927
984
* and then apply the patch to your nginx source tree that fixes an
928
985
important bug in the mainline Nginx core:
929
986
https://raw.github.com/agentzh/ngx_openresty/master/patches/nginx-1.
930
- 4.1-upstream_truncation.patch
987
+ 4.2-upstream_truncation.patch (you do NOT need this patch if you are
988
+ using nginx 1.5.3 and later versions.)
931
989
932
990
* after that, download the latest version of the release tarball of
933
991
this module from srcache-nginx-module file list
934
992
(<http://github.com/agentzh/srcache-nginx-module/tags>),
935
993
936
994
* and finally build the Nginx source with this module
937
995
938
- wget 'http://nginx.org/download/nginx-1.4.1 .tar.gz'
939
- tar -xzvf nginx-1.4.1 .tar.gz
940
- cd nginx-1.4.1 /
996
+ wget 'http://nginx.org/download/nginx-1.4.3 .tar.gz'
997
+ tar -xzvf nginx-1.4.3 .tar.gz
998
+ cd nginx-1.4.3 /
941
999
942
1000
# Here we assume you would install you nginx under /opt/nginx/.
943
1001
./configure --prefix=/opt/nginx \
@@ -949,7 +1007,7 @@ Installation
949
1007
Compatibility
950
1008
The following versions of Nginx should work with this module:
951
1009
952
- * 1.4.x (last tested: 1.4.1 )
1010
+ * 1.4.x (last tested: 1.4.3 )
953
1011
954
1012
* 1.3.x (last tested: 1.3.7)
955
1013
0 commit comments