From 719028ce5e2af1efa3967b81d67a04e994956b20 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 22 Jan 2012 12:49:41 +1100 Subject: [PATCH] (#11667) add try_files support in vhost and location directives Try_files is how NGINX files the files to serve particularly in a fallback mode. Using an array for try_files will interate through these options in the generated configuration file. --- manifests/resource/location.pp | 2 ++ manifests/resource/vhost.pp | 19 +++++++++++-------- templates/vhost/vhost_location_directory.erb | 4 ++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/manifests/resource/location.pp b/manifests/resource/location.pp index 1e650b9..5155bcd 100644 --- a/manifests/resource/location.pp +++ b/manifests/resource/location.pp @@ -11,6 +11,7 @@ # [*proxy*] - Proxy server(s) for a location to connect to. Accepts a single value, can be used in conjunction # with nginx::resource::upstream # [*ssl*] - Indicates whether to setup SSL bindings for this location. +# [*try_files*] - An array of file locations to try # [*option*] - Reserved for future use # # Actions: @@ -31,6 +32,7 @@ define nginx::resource::location( $index_files = ['index.html', 'index.htm', 'index.php'], $proxy = undef, $ssl = false, + $try_files = undef, $option = undef, $location ) { diff --git a/manifests/resource/vhost.pp b/manifests/resource/vhost.pp index 41ba742..bf4b222 100644 --- a/manifests/resource/vhost.pp +++ b/manifests/resource/vhost.pp @@ -17,6 +17,7 @@ # [*ssl_cert*] - Pre-generated SSL Certificate file to reference for SSL Support. This is not generated by this module. # [*ssl_key*] - Pre-generated SSL Key file to reference for SSL Support. This is not generated by this module. # [*www_root*] - Specifies the location on disk for files to be read from. Cannot be set in conjunction with $proxy +# [*try_files*] - Specifies the locations for files to be checked as an array. Cannot be used in conjuction with $proxy. # # Actions: # @@ -42,7 +43,8 @@ define nginx::resource::vhost( $ssl_key = undef, $proxy = undef, $index_files = ['index.html', 'index.htm', 'index.php'], - $www_root = undef + $www_root = undef, + $try_files = undef ) { File { @@ -77,13 +79,14 @@ define nginx::resource::vhost( # Create the default location reference for the vHost nginx::resource::location {"${name}-default": - ensure => $ensure, - vhost => $name, - ssl => $ssl, - location => '/', - proxy => $proxy, - www_root => $www_root, - notify => Class['nginx::service'], + ensure => $ensure, + vhost => $name, + ssl => $ssl, + location => '/', + proxy => $proxy, + try_files => $try_files, + www_root => $www_root, + notify => Class['nginx::service'], } # Create a proper file close stub. diff --git a/templates/vhost/vhost_location_directory.erb b/templates/vhost/vhost_location_directory.erb index 0640605..4e60f9a 100644 --- a/templates/vhost/vhost_location_directory.erb +++ b/templates/vhost/vhost_location_directory.erb @@ -1,4 +1,8 @@ location <%= location %> { root <%= www_root %>; index <% index_files.each do |i| %> <%= i %> <% end %>; + + <% if has_variable?("try_files") then %> + try_files <% try_files.each do |try| -%> <%= try %> <% end -%>; + <% end %> }