From 945a9f2af32c6ff47dfe4b825d2bb680d7124ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20M=E4kinen?= Date: Tue, 7 May 2013 10:03:22 +0300 Subject: [PATCH] apache: Added support for proxy http sites. --- apache/manifests/debian.pp | 32 +++++++++++++++----------- apache/manifests/init.pp | 13 ++++++++++- apache/manifests/redhat.pp | 34 ++++++++++++++++------------ apache/templates/proxy.http.conf.erb | 10 ++++++++ 4 files changed, 61 insertions(+), 28 deletions(-) create mode 100644 apache/templates/proxy.http.conf.erb diff --git a/apache/manifests/debian.pp b/apache/manifests/debian.pp index c05721e..94a7710 100644 --- a/apache/manifests/debian.pp +++ b/apache/manifests/debian.pp @@ -100,19 +100,21 @@ define apache::debian::site($aliases, $root, $redirect) { $site_confdir = "/etc/apache2/sites-enabled/${site_fqdn}.d" if !$redirect { - if $root { - file { "/srv/www/http/${site_fqdn}": - ensure => link, - target => $root, - before => File[$site_conf], - } - } else { - file { "/srv/www/http/${site_fqdn}": - ensure => directory, - mode => "0755", - owner => root, - group => root, - before => File[$site_conf], + if !$proxy { + if $root { + file { "/srv/www/http/${site_fqdn}": + ensure => link, + target => $root, + before => File[$site_conf], + } + } else { + file { "/srv/www/http/${site_fqdn}": + ensure => directory, + mode => "0755", + owner => root, + group => root, + before => File[$site_conf], + } } } @@ -138,6 +140,10 @@ define apache::debian::site($aliases, $root, $redirect) { File[$site_conf] { content => "\n ServerName ${site_fqdn}\n Redirect permanent / ${redirect}\n\n", } + } elsif $proxy { + File[$site_conf] { + content => template("apache/proxy.http.conf.erb"), + } } else { File[$site_conf] { content => template("apache/site.http.conf.erb"), diff --git a/apache/manifests/init.pp b/apache/manifests/init.pp index 6ad497d..7bc9f6a 100644 --- a/apache/manifests/init.pp +++ b/apache/manifests/init.pp @@ -154,6 +154,8 @@ class apache::server inherits apache::common { # Path to document root. Defaults to /srv/www/http/$fqdn # $redirect: # Add redirect to given URL. +# $proxy: +# Proxy site to given URL. # # === Sample usage # @@ -163,8 +165,15 @@ class apache::server inherits apache::common { # apache::site { "www.example.com": # root => "/roles/prteam/public/public_access", # } +# apache::site { "www2.example.com": +# proxy => "http://www.example.com", +# } # -define apache::site($aliases="", $root="", $redirect="") { +define apache::site($aliases="", $root="", $redirect="", $proxy="") { + + if $redirect and $proxy { + fail("cannot define both \$redirect and \$proxy for apache::site (${name})") + } case $::operatingsystem { "debian","ubuntu": { @@ -172,6 +181,7 @@ define apache::site($aliases="", $root="", $redirect="") { aliases => $aliases, root => $root, redirect => $redirect, + proxy => $proxy, } } "centos","redhat","fedora": { @@ -179,6 +189,7 @@ define apache::site($aliases="", $root="", $redirect="") { aliases => $aliases, root => $root, redirect => $redirect, + proxy => $proxy, } } default: { diff --git a/apache/manifests/redhat.pp b/apache/manifests/redhat.pp index 11f89c7..2aefc68 100644 --- a/apache/manifests/redhat.pp +++ b/apache/manifests/redhat.pp @@ -45,7 +45,7 @@ class apache::redhat::server { } -define apache::redhat::site($aliases, $root, $redirect) { +define apache::redhat::site($aliases, $root, $redirect, $proxy) { if $name == "default" { $site_fqdn = $homename @@ -57,19 +57,21 @@ define apache::redhat::site($aliases, $root, $redirect) { $site_confdir = "/etc/httpd/site.http.d/${site_fqdn}.d" if !$redirect { - if $root { - file { "/srv/www/http/${site_fqdn}": - ensure => link, - target => $root, - before => File[$site_conf], - } - } else { - file { "/srv/www/http/${site_fqdn}": - ensure => directory, - mode => "0755", - owner => root, - group => root, - before => File[$site_conf], + if !$proxy { + if $root { + file { "/srv/www/http/${site_fqdn}": + ensure => link, + target => $root, + before => File[$site_conf], + } + } else { + file { "/srv/www/http/${site_fqdn}": + ensure => directory, + mode => "0755", + owner => root, + group => root, + before => File[$site_conf], + } } } @@ -96,6 +98,10 @@ define apache::redhat::site($aliases, $root, $redirect) { File[$site_conf] { content => "\n ServerName ${site_fqdn}\n Redirect permanent / ${redirect}\n\n", } + } elsif $proxy { + File[$site_conf] { + content => template("apache/proxy.http.conf.erb"), + } } else { File[$site_conf] { content => template("apache/site.http.conf.erb"), diff --git a/apache/templates/proxy.http.conf.erb b/apache/templates/proxy.http.conf.erb new file mode 100644 index 0000000..06b4c83 --- /dev/null +++ b/apache/templates/proxy.http.conf.erb @@ -0,0 +1,10 @@ + + ServerName <%= @site_fqdn %> +<% if @aliases != "" -%> + ServerAlias <%= @aliases %> +<% end -%> + ErrorLog /srv/www/log/http/<%= @site_fqdn %>/error_log + CustomLog /srv/www/log/http/<%= @site_fqdn %>/access_log combined + ProxyPass / <%= @proxy %>/ + ProxyPassReverse / <%= @proxy %>/ +