From 54259659d67ec095539378c9f79161fa015dd372 Mon Sep 17 00:00:00 2001
From: Gabriel Monnerat <gabriel@tiolive.com>
Date: Fri, 5 Aug 2011 13:27:44 -0300
Subject: [PATCH] If the cache is enabled, the varnish and stunnel will be
 added between frontend and backend. With this, the connection will be:
 frontend > varnish > stunnel > backend.

---
 slapos/recipe/apache/__init__.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/slapos/recipe/apache/__init__.py b/slapos/recipe/apache/__init__.py
index a4b626488..f65fd5a86 100644
--- a/slapos/recipe/apache/__init__.py
+++ b/slapos/recipe/apache/__init__.py
@@ -96,18 +96,24 @@ class Recipe(BaseSlapRecipe):
           slave_port = 80
         service_name = "varnish_%s" % reference
         varnish_ip = self.getLocalIPv4Address()
+        stunnel_port = base_varnish_port + 1
         self.installVarnishCache(service_name,
           ip=varnish_ip,
           port=base_varnish_port,
           control_port=base_varnish_control_port,
-          backend_host=slave_host,
-          backend_port=slave_port,
+          backend_host=varnish_ip,
+          backend_port=stunnel_port,
           size="1G")
 
         service_dict[service_name] = dict(public_ip=varnish_ip,
-            public_port=base_varnish_port,
+            public_port=stunnel_port,
             private_ip=slave_host,
             private_port=slave_port)
+        rewrite_rule_list.append("%s http://%s:%s" % \
+            (reference.replace("-", ""), varnish_ip, base_varnish_port))
+      else:
+        rewrite_rule_list.append("%s %s" % (reference.replace("-", ""), url))
+
     if service_dict != {}:
       self.installStunnel(service_dict,
         certificate, key,
-- 
2.30.9