Commits

Éric Veiras Galisson committed 435f11f

nginx::site::proxy can have multiple upstream definitions with several servers each

Comments (0)

Files changed (3)

         server_name (mandatory): 
             the virtualhost name
 
-        upstream (mandatory):
-            the upstream server, an ip (w.x.y.z) or a unix socket (unix:/path/to/socket)
+        upstreams (mandatory):
+            the upstream server(s), specifying an hash of upstream name and at least one server, like
+                upstreams => { "upstream1" => "server1",
+                               "upstream2" => ["server2", "server3"] }
+
+            the server is an ip (w.x.y.z) or a unix socket (unix:/path/to/socket) 
             with eventual options (like fail_timeout...)
 
         root_dir (mandatory):

nginx/manifests/site/proxy.pp

 define nginx::site::proxy($server_name='',
                           $server_aliases=[],
                           $port='80',
-                          $upstream='',
+                          $upstreams=[],
                           $root_dir='',
                           $location_blocks={},
                           $default_vhost=false,

nginx/templates/proxy.erb

 #
 # module nginx
 
-upstream <%= server_name %> {
-    server              <%= upstream %>;
+<% upstreams.each_pair do |server_name, upstream_servers| %>
+upstream <%= server_name %> {<% upstream_servers.each do |upstream_server| %>
+    server              <%= upstream_server %>;<% end %>
 }
+<% end %>
 
 server {        
     listen              <%= define_port %>;