Skip to content

Commit

Permalink
Add support for locations with only custom directives
Browse files Browse the repository at this point in the history
  • Loading branch information
jamorton committed Jul 3, 2013
1 parent 063f6b5 commit d838228
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
17 changes: 11 additions & 6 deletions manifests/resource/location.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
# [*ssl_only*] - Required if the SSL and normal vHost have the same port.
# [*location_alias*] - Path to be used as basis for serving requests for this location
# [*stub_status*] - If true it will point configure module stub_status to provide nginx stats on location
# [*location_cfg_prepend*] - It expects a hash with custom directives to put before anything else inside location
# [*location_cfg_append*] - It expects a hash with custom directives to put after everything else inside location
# [*custom_cfg*] - Expects a hash with custom directives, cannot be used with other location types (proxy, fastcgi, root, or stub_status)
# [*location_cfg_prepend*] - Expects a hash with extra directives to put before anything else inside location (used with all other types except custom_cfg)
# [*location_cfg_append*] - Expects a hash with extra directives to put after everything else inside location (used with all other types except custom_cfg)
# [*try_files*] - An array of file locations to try
# [*option*] - Reserved for future use
# [*proxy_cache*] - This directive sets name of zone for caching.
Expand Down Expand Up @@ -77,6 +78,7 @@
$location_alias = undef,
$option = undef,
$stub_status = undef,
$custom_cfg = undef,
$location_cfg_prepend = undef,
$location_cfg_append = undef,
$try_files = undef,
Expand All @@ -98,14 +100,15 @@
default => file,
}

notice "custom_cfg ${custom_cfg}"

## Check for various error conditions
if ($vhost == undef) {
fail('Cannot create a location reference without attaching to a virtual host')
}
if (($www_root == undef) and ($proxy == undef) and ($location_alias == undef) and ($stub_status == undef) and ($fastcgi == undef)) {
fail('Cannot create a location reference without a www_root, proxy, location_alias, fastcgi or stub_status defined')
if (($www_root == undef) and ($proxy == undef) and ($location_alias == undef) and ($stub_status == undef) and ($fastcgi == undef) and ($custom_cfg == undef)) {
fail('Cannot create a location reference without a www_root, proxy, location_alias, fastcgi, stub_status, or custom_cfg defined')
}

if (($www_root != undef) and ($proxy != undef)) {
fail('Cannot define both directory and proxy in a virtual host')
}
Expand All @@ -119,8 +122,10 @@
$content_real = template('nginx/vhost/vhost_location_stub_status.erb')
} elsif ($fastcgi != undef) {
$content_real = template('nginx/vhost/vhost_location_fastcgi.erb')
} else {
} elsif ($www_root != undef) {
$content_real = template('nginx/vhost/vhost_location_directory.erb')
} else {
$content_real = template('nginx/vhost/vhost_location_empty.erb')
}

## Create stubs for vHost File Fragment Pattern
Expand Down
5 changes: 5 additions & 0 deletions templates/vhost/vhost_location_empty.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
location <%= location %> {
<% custom_cfg.each do |key,value| -%>
<%= key %> <%= value %>;
<% end -%>
}

0 comments on commit d838228

Please sign in to comment.