aboutsummaryrefslogtreecommitdiff
path: root/README
diff options
context:
space:
mode:
Diffstat (limited to 'README')
-rw-r--r--README135
1 files changed, 76 insertions, 59 deletions
diff --git a/README b/README
index f730269..4c22ea4 100644
--- a/README
+++ b/README
@@ -20,84 +20,101 @@ This version supports MySQL and PostgreSQL databases.
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);
- }
-}
+ 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 3.x 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);
+ }
+ }
+
+VCL 4.0 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 != "") {
+ return(synth(301, "Redirect"));
+ }
+ }
+
+ sub vcl_synth {
+ if (resp.status == 301) {
+ set resp.http.Location = req.http.X-Redirect-To;
+ 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)
-)
+ 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"});
-}
+ 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:
+Both Varnish 3.x and 4.x are supported. 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.
+ ./configure --with-varnish-source=/usr/src/varnish-3.0.1
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:
+This will build the module. Finally, do the following command as root:
make install
-
-
+
* Bug reporting
Send bug reports and suggestions to <gray@gnu.org>
@@ -119,6 +136,6 @@ Copyright (C) 2013-2014 Sergey Poznyakoff
Local Variables:
mode: outline
-paragraph-separate: "[ ]*$"
+paragraph-separate: "[ ]*$"
version-control: never
End:

Return to:

Send suggestions and report system problems to the System administrator.