From e419006b7448c3a3a640aaac132f0ab6a7d43554 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Thu, 8 Nov 2012 14:15:28 -0800 Subject: [PATCH] Add try_files option Nginx supports a option via http://wiki.nginx.org/HttpCoreModule#try_files and this adds this as a parameter --- manifests/resource/location.pp | 2 ++ manifests/resource/vhost.pp | 3 +++ templates/vhost/vhost_location_directory.erb | 3 +++ templates/vhost/vhost_ssl_header.erb | 6 ++++-- tests/vhost.pp | 10 +++++++++- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/manifests/resource/location.pp b/manifests/resource/location.pp index 33d951d31..8949f9054 100644 --- a/manifests/resource/location.pp +++ b/manifests/resource/location.pp @@ -17,6 +17,7 @@ # [*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 +# [*try_files*] - An array of file locations to try # [*option*] - Reserved for future use # # Actions: @@ -60,6 +61,7 @@ $stub_status = undef, $location_cfg_prepend = undef, $location_cfg_append = undef, + $try_files = undef, $location ) { File { diff --git a/manifests/resource/vhost.pp b/manifests/resource/vhost.pp index 316fc0fbc..8b291722e 100644 --- a/manifests/resource/vhost.pp +++ b/manifests/resource/vhost.pp @@ -25,6 +25,7 @@ # [*www_root*] - Specifies the location on disk for files to be read from. Cannot be set in conjunction with $proxy # [*rewrite_www_to_non_www*] - Adds a server directive and rewrite rule to rewrite www.domain.com to domain.com in order to avoid # duplicate content (SEO); +# [*try_files*] - Specifies the locations for files to be checked as an array. Cannot be used in conjuction with $proxy. # # Actions: # @@ -59,6 +60,7 @@ $rewrite_www_to_non_www = false, $location_cfg_prepend = undef, $location_cfg_append = undef, + $try_files = undef ) { File { @@ -106,6 +108,7 @@ location => '/', proxy => $proxy, proxy_read_timeout => $proxy_read_timeout, + try_files => $try_files, www_root => $www_root, notify => Class['nginx::service'], } diff --git a/templates/vhost/vhost_location_directory.erb b/templates/vhost/vhost_location_directory.erb index 0e066e961..f73fa11d4 100644 --- a/templates/vhost/vhost_location_directory.erb +++ b/templates/vhost/vhost_location_directory.erb @@ -3,6 +3,9 @@ <%= key %> <%= value %>; <% end -%><% end -%> root <%= www_root %>; + <% if has_variable?("try_files") then %> + try_files <% try_files.each do |try| -%> <%= try %> <% end -%>; + <% end %> index <% index_files.each do |i| %> <%= i %> <% end %>; <% if @location_cfg_append -%><% location_cfg_append.each do |key,value| -%> <%= key %> <%= value %>; diff --git a/templates/vhost/vhost_ssl_header.erb b/templates/vhost/vhost_ssl_header.erb index d5d30a90d..fc17e88b5 100644 --- a/templates/vhost/vhost_ssl_header.erb +++ b/templates/vhost/vhost_ssl_header.erb @@ -1,7 +1,9 @@ server { listen <%= ssl_port %>; - <% if ipv6_enable == 'true' && (defined? ipaddress6) %>listen [<%= ipv6_listen_ip %>]:<%= ipv6_listen_port %> default ipv6only=on;<% end %> - server_name <%= name %>; + <% if ipv6_enable == 'true' && (defined? ipaddress6) %> + listen [<%= ipv6_listen_ip %>]:<%= ipv6_listen_port %> <% if @ipv6_listen_options %><%= ipv6_listen_options %><% end %> ipv6only=on; + <% end %> + server_name <%= rewrite_www_to_non_www ? name.gsub(/^www\./, '') : server_name.join(" ") %>; ssl on; ssl_certificate <%= ssl_cert %>; diff --git a/tests/vhost.pp b/tests/vhost.pp index 40658d937..78b050bfd 100644 --- a/tests/vhost.pp +++ b/tests/vhost.pp @@ -1,4 +1,4 @@ -include nginix +include nginx nginx::resource::vhost { 'test.local': ensure => present, @@ -6,3 +6,11 @@ proxy => 'http://proxypass', } +nginx::resource::vhost { 'test.local:8080': + listen_port => 8080, + server_name => 'test.local', + ensure => present, + ipv6_enable => 'true', + proxy => 'http://proxypass', +} +