diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-07-10 15:16:05 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-07-12 11:50:07 +0300 |
commit | 8afb551c895d6870b0d4f427fa8205ae45ad0bf9 (patch) | |
tree | 6e208d7a54d2845035b366a906b35b390ccce96a /README | |
download | vmod-dbrw-8afb551c895d6870b0d4f427fa8205ae45ad0bf9.tar.gz vmod-dbrw-8afb551c895d6870b0d4f427fa8205ae45ad0bf9.tar.bz2 |
Initial commit
Diffstat (limited to 'README')
-rw-r--r-- | README | 107 |
1 files changed, 107 insertions, 0 deletions
@@ -0,0 +1,107 @@ | |||
1 | * Overview | ||
2 | |||
3 | Vmod-dbrw is a Varnish Cache module implementing database-driven | ||
4 | rewrite rules. Its intended use is for web sites that need an | ||
5 | exceedingly big number of redirect and/or rewrite rules. Vmod-dbrw | ||
6 | allows you to keep all rules in an SQL database of arbitrary | ||
7 | structure, considerably speeding up their handling. Another advantage | ||
8 | of this approach is that rewrite rules stored in a database are easier | ||
9 | to maintain. | ||
10 | |||
11 | This version supports MySQL databases. Support for PostgreSQL will be | ||
12 | added soon. | ||
13 | |||
14 | * Example | ||
15 | |||
16 | ** Simplest case | ||
17 | |||
18 | The redirection database has the following structure | ||
19 | |||
20 | CREATE TABLE redirects ( | ||
21 | host varchar(255) NOT NULL DEFAULT '', | ||
22 | url varchar(255) NOT NULL DEFAULT '', | ||
23 | dest varchar(255) DEFAULT NULL, | ||
24 | PRIMARY KEY (host,url) | ||
25 | ); | ||
26 | |||
27 | VCL code: | ||
28 | |||
29 | import dbrw; | ||
30 | |||
31 | sub vcl_init { | ||
32 | dbrw.config("mysql", "database=dbname;user=varnish;debug=1", | ||
33 | "SELECT dest FROM redirects WHERE host='$host' AND url='$url'"); | ||
34 | } | ||
35 | |||
36 | sub vcl_recv { | ||
37 | set req.http.X-Redirect-To = | ||
38 | dbrw.rewrite("host=" + req.http.Host + ";" + | ||
39 | "url=" + req.url); | ||
40 | if (req.http.X-Redirect-To) { | ||
41 | error(750, "Redirect"); | ||
42 | } | ||
43 | } | ||
44 | |||
45 | sub vcl_error { | ||
46 | if (obj.status == 750) { | ||
47 | set obj.http.Location = req.http.X-Redirect-To; | ||
48 | set obj.status = 301; | ||
49 | return (deliver); | ||
50 | } | ||
51 | } | ||
52 | |||
53 | ** More complex case: rewrites | ||
54 | |||
55 | Table structure: | ||
56 | |||
57 | CREATE TABLE rewrite ( | ||
58 | host varchar(255) NOT NULL DEFAULT '', | ||
59 | url varchar(255) NOT NULL DEFAULT '', | ||
60 | dest varchar(255) DEFAULT NULL, | ||
61 | value varchar(255) DEFAULT NULL, | ||
62 | pattern varchar(255) DEFAULT NULL, | ||
63 | KEY source (host,url) | ||
64 | ) | ||
65 | |||
66 | VCL code differs only in definition of the vcl_init: | ||
67 | |||
68 | sub vcl_init { | ||
69 | dbrw.config("mysql", "database=varnish;user=varnish;debug=10", | ||
70 | {"SELECT dest,pattern,value FROM rewrite | ||
71 | WHERE host='$host' and '$url' like url"}); | ||
72 | } | ||
73 | |||
74 | * Installation | ||
75 | |||
76 | In order to compile the package you need to have Varnish source tree. | ||
77 | At least Varnish 3.0.1 is required. Supposing that the varnish source tree | ||
78 | is available under /usr/src/varnish-3.0.1, run: | ||
79 | |||
80 | ./configure --with-varnish-source=/usr/src/varnish-3.0.1 --with-vmod-dir | ||
81 | |||
82 | The first option tells configure where Varnish sources reside, the | ||
83 | second one (--with-vmod-dir) instructs it to place created module | ||
84 | files to the standard Varnish module directory. | ||
85 | |||
86 | Once configured, do | ||
87 | |||
88 | make | ||
89 | |||
90 | This will build the module. After this step you can optionally run | ||
91 | 'make test' to test the package. | ||
92 | |||
93 | Finally, do the following command as root: | ||
94 | |||
95 | make install | ||
96 | |||
97 | |||
98 | * Bug reporting | ||
99 | |||
100 | Send bug reports and suggestions to <gray@gnu.org> | ||
101 | |||
102 | |||
103 | Local Variables: | ||
104 | mode: outline | ||
105 | paragraph-separate: "[ ]*$" | ||
106 | version-control: never | ||
107 | End: | ||