(#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.
This commit is contained in:
Daniel Black 2012-01-22 12:49:41 +11:00
parent 14d6281d5a
commit 719028ce5e
3 changed files with 17 additions and 8 deletions

View file

@ -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
) {

View file

@ -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 {
@ -82,6 +84,7 @@ define nginx::resource::vhost(
ssl => $ssl,
location => '/',
proxy => $proxy,
try_files => $try_files,
www_root => $www_root,
notify => Class['nginx::service'],
}

View file

@ -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 %>
}