This repository was archived by the owner on Sep 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathREADME
More file actions
134 lines (96 loc) · 2.3 KB
/
README
File metadata and controls
134 lines (96 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
nginx HTTP redis module
--
Description:
--
The nginx HTTP redis module for caching with redis,
http://code.google.com/p/redis/.
The redis protocol
(http://code.google.com/p/redis/wiki/ProtocolSpecification)
not yet fully implemented, but GET and SELECT commands only.
Installation:
--
You'll need to re-compile Nginx from source to include this module.
Modify your compile of Nginx by adding the following directive
(modified to suit your path of course):
./configure --add-module=/absolute/path/to/ngx_http_redis
make
make install
Usage:
--
Example 1.
http
{
...
server {
location / {
set $redis_key "$uri?$args";
redis_pass 127.0.0.1:6379;
error_page 404 502 504 = @fallback;
}
location @fallback {
proxy_pass backed;
}
}
}
Example 2.
Capture User-Agent from an HTTP header, query to redis database
for lookup appropriate backend.
Eval module (http://www.grid.net.ru/nginx/eval.en.html) required.
http
{
...
upstream redis {
server 127.0.0.1:6379;
}
server {
...
location / {
eval_escalate on;
eval $answer {
set $redis_key "$http_user_agent";
redis_pass redis;
}
proxy_pass $answer;
}
...
}
}
Example 3.
Compile nginx with ngx_http_redis and ngx_http_gunzip_filter modules
(http://mdounin.ru/hg/ngx_http_gunzip_filter_module/).
Gzip content and put it into redis database.
% cat index.html
<html><body>Hello from redis!</body></html>
% gzip index.html
% cat index.html.gz | redis-cli -x set /index.html
OK
% cat index.html.gz | redis-cli -x set /
OK
%
Using following configuration nginx get data from redis database and
gunzip it.
http
{
...
upstream redis {
server 127.0.0.1:6379;
}
server {
...
location / {
gunzip on;
redis_gzip_flag 1;
set $redis_key "$uri";
redis_pass redis;
}
}
Thanks to:
--
Maxim Dounin
Vsevolod Stakhov
Ezra Zygmuntowicz
Special thanks to:
--
Evan Miller for his "Guide To Nginx Module Development" and "Advanced Topics
In Nginx Module Development"
Valery Kholodkov for his "Nginx modules development"