Skip to content

Commit

Permalink
Merge pull request #17 from lboynton/nginx-alias
Browse files Browse the repository at this point in the history
Add alias support
  • Loading branch information
jfryman committed Oct 1, 2012
2 parents 33eb32f + 1d50d9e commit af4006c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions manifests/resource/location.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -34,6 +35,7 @@
$proxy = undef,
$proxy_read_timeout = $nginx::params::nx_proxy_read_timeout,
$ssl = false,
$location_alias = undef,
$option = undef,
$location
) {
Expand All @@ -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')
}
Expand All @@ -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')
Expand Down
3 changes: 3 additions & 0 deletions templates/vhost/vhost_location_alias.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
location <%= location %> {
alias <%= location_alias %>;
}
8 changes: 8 additions & 0 deletions tests/location_alias.pp
Original file line number Diff line number Diff line change
@@ -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',
}

0 comments on commit af4006c

Please sign in to comment.