Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
t/ | H | 03-Nov-2011 | - | 631 | 432 | |
AUTHOR | H A D | 14-May-2018 | 73 | 3 | 2 | |
CHANGES | H A D | 14-May-2018 | 3.7 KiB | 121 | 69 | |
LICENSE | H A D | 14-May-2018 | 1.3 KiB | 26 | 25 | |
README | H A D | 14-May-2018 | 2.7 KiB | 151 | 109 | |
config | H A D | 21-Feb-2016 | 490 | 19 | 16 | |
ngx_http_redis_module.c | H A D | 13-May-2018 | 29.1 KiB | 992 | 689 |
README
1nginx HTTP redis module 2-- 3 4Description: 5-- 6 7The nginx HTTP redis module for caching with redis, 8http://code.google.com/p/redis/. 9 10The redis protocol 11(http://code.google.com/p/redis/wiki/ProtocolSpecification) 12not yet fully implemented, but AUTH, GET and SELECT commands only. 13 14 15 16Installation: 17-- 18 19You'll need to re-compile Nginx from source to include this module. 20Modify your compile of Nginx by adding the following directive 21(modified to suit your path of course): 22 23./configure --add-module=/absolute/path/to/ngx_http_redis 24make 25make install 26 27 28 29Usage: 30-- 31 32Example 1. 33 34 35http 36{ 37 ... 38 server { 39 location / { 40 set $redis_key "$uri?$args"; 41 redis_pass 127.0.0.1:6379; 42 error_page 404 502 504 = @fallback; 43 } 44 45 location @fallback { 46 proxy_pass backed; 47 } 48 } 49} 50 51 52Example 2. 53 54Capture User-Agent from an HTTP header, query to redis database 55for lookup appropriate backend. 56 57Eval module (http://www.grid.net.ru/nginx/eval.en.html) required. 58 59http 60{ 61 ... 62 upstream redis { 63 server 127.0.0.1:6379; 64 } 65 66 server { 67 ... 68 location / { 69 70 eval_escalate on; 71 72 eval $answer { 73 set $redis_key "$http_user_agent"; 74 redis_pass redis; 75 } 76 77 proxy_pass $answer; 78 } 79 ... 80 } 81} 82 83 84Example 3. 85 86Compile nginx with ngx_http_redis and ngx_http_gunzip_filter modules 87(http://mdounin.ru/hg/ngx_http_gunzip_filter_module/). 88Gzip content and put it into redis database. 89 90% cat index.html 91<html><body>Hello from redis!</body></html> 92% gzip index.html 93% cat index.html.gz | redis-cli -x set /index.html 94OK 95% cat index.html.gz | redis-cli -x set / 96OK 97% 98 99Using following configuration nginx get data from redis database and 100gunzip it. 101 102http 103{ 104 ... 105 upstream redis { 106 server 127.0.0.1:6379; 107 } 108 109 server { 110 ... 111 location / { 112 gunzip on; 113 redis_gzip_flag 1; 114 set $redis_key "$uri"; 115 redis_pass redis; 116 } 117} 118 119 120Example 4. 121 122The same as Example 1 but with AUTH. 123 124http 125{ 126 ... 127 server { 128 location / { 129 set $redis_auth somepasswd; 130 set $redis_key "$uri?$args"; 131 redis_pass 127.0.0.1:6379; 132 error_page 404 502 504 = @fallback; 133 } 134} 135 136 137Thanks to: 138-- 139 140Maxim Dounin 141Vsevolod Stakhov 142Ezra Zygmuntowicz 143 144 145 146Special thanks to: 147-- 148Evan Miller for his "Guide To Nginx Module Development" and "Advanced Topics 149In Nginx Module Development" 150Valery Kholodkov for his "Nginx modules development" 151