From 1d50d9ea05321c31e37be5261d724df709737b2f Mon Sep 17 00:00:00 2001 From: Lee Boynton Date: Mon, 24 Sep 2012 16:21:35 +0100 Subject: [PATCH] Add alias support --- manifests/resource/location.pp | 8 ++++++-- templates/vhost/vhost_location_alias.erb | 3 +++ tests/location_alias.pp | 8 ++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 templates/vhost/vhost_location_alias.erb create mode 100644 tests/location_alias.pp diff --git a/manifests/resource/location.pp b/manifests/resource/location.pp index a6810c2a2..f52ee9c01 100644 --- a/manifests/resource/location.pp +++ b/manifests/resource/location.pp @@ -12,6 +12,7 @@ # with nginx::resource::upstream # [*proxy_read_timeout*] - Override the default the proxy read timeout value of 90 seconds # [*ssl*] - Indicates whether to setup SSL bindings for this location. +# [*location_alias*] - Path to be used as basis for serving requests for this location # [*option*] - Reserved for future use # # Actions: @@ -34,6 +35,7 @@ $proxy = undef, $proxy_read_timeout = $nginx::params::nx_proxy_read_timeout, $ssl = false, + $location_alias = undef, $option = undef, $location ) { @@ -53,6 +55,8 @@ # Use proxy template if $proxy is defined, otherwise use directory template. if ($proxy != undef) { $content_real = template('nginx/vhost/vhost_location_proxy.erb') + } elsif ($location_alias != undef) { + $content_real = template('nginx/vhost/vhost_location_alias.erb') } else { $content_real = template('nginx/vhost/vhost_location_directory.erb') } @@ -61,8 +65,8 @@ if ($vhost == undef) { fail('Cannot create a location reference without attaching to a virtual host') } - if (($www_root == undef) and ($proxy == undef)) { - fail('Cannot create a location reference without a www_root or proxy defined') + if (($www_root == undef) and ($proxy == undef) and ($location_alias == undef)) { + fail('Cannot create a location reference without a www_root, proxy or location_alias defined') } if (($www_root != undef) and ($proxy != undef)) { fail('Cannot define both directory and proxy in a virtual host') diff --git a/templates/vhost/vhost_location_alias.erb b/templates/vhost/vhost_location_alias.erb new file mode 100644 index 000000000..bc7f27e80 --- /dev/null +++ b/templates/vhost/vhost_location_alias.erb @@ -0,0 +1,3 @@ + location <%= location %> { + alias <%= location_alias %>; + } diff --git a/tests/location_alias.pp b/tests/location_alias.pp new file mode 100644 index 000000000..ac774bafe --- /dev/null +++ b/tests/location_alias.pp @@ -0,0 +1,8 @@ +include nginx + +nginx::resource::location { 'www.test.com-alias': + ensure => present, + location => '/some/url', + location_alias => '/new/url/', + vhost => 'www.test.com', +}