diff options
Diffstat (limited to 'README')
-rw-r--r-- | README | 107 |
1 files changed, 107 insertions, 0 deletions
@@ -0,0 +1,107 @@ +* Overview + +Vmod-dbrw is a Varnish Cache module implementing database-driven +rewrite rules. Its intended use is for web sites that need an +exceedingly big number of redirect and/or rewrite rules. Vmod-dbrw +allows you to keep all rules in an SQL database of arbitrary +structure, considerably speeding up their handling. Another advantage +of this approach is that rewrite rules stored in a database are easier +to maintain. + +This version supports MySQL databases. Support for PostgreSQL will be +added soon. + +* Example + +** Simplest case + +The redirection database has the following structure + +CREATE TABLE redirects ( + host varchar(255) NOT NULL DEFAULT '', + url varchar(255) NOT NULL DEFAULT '', + dest varchar(255) DEFAULT NULL, + PRIMARY KEY (host,url) +); + +VCL code: + +import dbrw; + +sub vcl_init { + dbrw.config("mysql", "database=dbname;user=varnish;debug=1", + "SELECT dest FROM redirects WHERE host='$host' AND url='$url'"); +} + +sub vcl_recv { + set req.http.X-Redirect-To = + dbrw.rewrite("host=" + req.http.Host + ";" + + "url=" + req.url); + if (req.http.X-Redirect-To) { + error(750, "Redirect"); + } +} + +sub vcl_error { + if (obj.status == 750) { + set obj.http.Location = req.http.X-Redirect-To; + set obj.status = 301; + return (deliver); + } +} + +** More complex case: rewrites + +Table structure: + +CREATE TABLE rewrite ( + host varchar(255) NOT NULL DEFAULT '', + url varchar(255) NOT NULL DEFAULT '', + dest varchar(255) DEFAULT NULL, + value varchar(255) DEFAULT NULL, + pattern varchar(255) DEFAULT NULL, + KEY source (host,url) +) + +VCL code differs only in definition of the vcl_init: + +sub vcl_init { + dbrw.config("mysql", "database=varnish;user=varnish;debug=10", + {"SELECT dest,pattern,value FROM rewrite + WHERE host='$host' and '$url' like url"}); +} + +* Installation + +In order to compile the package you need to have Varnish source tree. +At least Varnish 3.0.1 is required. Supposing that the varnish source tree +is available under /usr/src/varnish-3.0.1, run: + + ./configure --with-varnish-source=/usr/src/varnish-3.0.1 --with-vmod-dir + +The first option tells configure where Varnish sources reside, the +second one (--with-vmod-dir) instructs it to place created module +files to the standard Varnish module directory. + +Once configured, do + + make + +This will build the module. After this step you can optionally run +'make test' to test the package. + +Finally, do the following command as root: + + make install + + +* Bug reporting + +Send bug reports and suggestions to <gray@gnu.org> + + +Local Variables: +mode: outline +paragraph-separate: "[ ]*$" +version-control: never +End: |