diff options
Diffstat (limited to 'config/varnish64')
-rw-r--r-- | config/varnish64/varnish.inc | 28 | ||||
-rw-r--r-- | config/varnish64/varnish_lb_directors.xml | 24 |
2 files changed, 46 insertions, 6 deletions
diff --git a/config/varnish64/varnish.inc b/config/varnish64/varnish.inc index a7009c7d..ec7ef0c4 100644 --- a/config/varnish64/varnish.inc +++ b/config/varnish64/varnish.inc @@ -5,6 +5,7 @@ part of pfSense (http://www.pfSense.com) Copyright (C) 2010 Scott Ullrich <sullrich@gmail.com> Copyright (C) 2011 Marcello Coutinho + Copyright (C) 2012 Marcio Carlos Antão All rights reserved. */ /* ========================================================================== */ @@ -129,8 +130,7 @@ function varnish_get_url_mappings_txt() { if($url['grace']) $directo_grace_time.=($url['grace']=="0s"?"return(pass);":"set req.grace=".$url['grace'].";"); $fieldtype = ($url['fieldtype']?$url['fieldtype']:"=="); - $req=($url['directorurl2']?"url":"http.host"); - $director_prefix=($url['directorurl'] && $url['directorurl2']?"^http://":""); + $director_prefix=($url['directorurl'] && $url['directorurl2']?"^http://":""); #check url if ( $url['directorurl'] || $url['directorurl2'] || $catch_all == "unset" ){ if ( $url['directorurl']== "" && $url['directorurl2']== "" ){ @@ -139,12 +139,30 @@ function varnish_get_url_mappings_txt() { $catch_all = "set"; $isfirst = false; } - else{ + else{ + if(!$isfirst) $urlmappings .= "\telse "; - $urlmappings .= "if (req.$req $fieldtype ".'"'.$url['directorurl'].$url['directorurl2'].'") {'."\n"; - #check failover + if(!$url['directorurl']) { + $urlmappings .= "if (req.url $fieldtype ".'"^'.$url['directorurl2'].'") {'."\n"; + } + else if (!$url['directorurl2']) { + $urlmappings .= "if (req.http.host $fieldtype ".'"'.$url['directorurl'].'") {'."\n"; + } + else { + $urlmappings .= "if (req.http.host $fieldtype ".'"'.$url['directorurl'].'"'." && req.url $fieldtype ".'"^'.$url['directorurl2'].'") {'."\n"; + } + $urlbackend = "\t\t\tset req.backend = ".$url['directorname'].";"; + + #check rewrite + if ($url['rewritehost']) { + $urlmappings .= "\t\t\tset req.http.host = regsub(req.http.host, ".'"'.$url['directorurl'].'",'.'"'.$url['rewritehost'].'")'.";\n"; + } + if ($url['rewriteurl']) { + $urlmappings .= "\t\t\tset req.url = regsub(req.url, ".'"'.$url['directorurl2'].'",'.'"^'.$url['rewriteurl'].'")'.";\n"; + } + #check failover if ($url['failover'] && $url['failover'] != $url['directorname']){ $tabs=($url['grace']?"\n\t\t\t":""); $urlfailover = "\t\t\tset req.backend = ".$url['failover'].";"; diff --git a/config/varnish64/varnish_lb_directors.xml b/config/varnish64/varnish_lb_directors.xml index 994320f3..4c46414e 100644 --- a/config/varnish64/varnish_lb_directors.xml +++ b/config/varnish64/varnish_lb_directors.xml @@ -111,7 +111,14 @@ <fielddescr>URL</fielddescr> <fieldname>directorurl2</fieldname> </columnitem> - + <columnitem> + <fielddescr>Rewrite Host</fielddescr> + <fieldname>rewritehost</fieldname> + </columnitem> + <columnitem> + <fielddescr>Rewrite url</fielddescr> + <fieldname>rewriteurl</fieldname> + </columnitem> <columnitem> <fielddescr>Type</fielddescr> <fieldname>directortype</fieldname> @@ -168,6 +175,21 @@ <type>input</type> <size>40</size> </field> + <field> + <fielddescr>Rewrite Host</fielddescr> + <fieldname>rewritehost</fieldname> + <description>Hint image.mysite.com</description> + <type>input</type> + <size>40</size> + </field> + <field> + <fielddescr>Rewrite URL</fielddescr> + <fieldname>rewriteurl</fieldname> + <description>Hint /images</description> + <type>input</type> + <size>40</size> + </field> + <field> <fielddescr>Req Grace</fielddescr> <fieldname>grace</fieldname> |