From 520eb23ffd9f6815aebe0f191e878b047efe85bf Mon Sep 17 00:00:00 2001 From: Daniel Black <daniel.black@openquery.com> Date: Thu, 19 Dec 2013 09:07:56 +1000 Subject: [PATCH 1/2] index_files to be defined at server level if specified in resource::vhost This partially avoids pitfall #2 (http://wiki.nginx.org/Pitfalls) --- manifests/resource/vhost.pp | 2 +- templates/vhost/vhost_header.erb | 3 +++ templates/vhost/vhost_ssl_header.erb | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/manifests/resource/vhost.pp b/manifests/resource/vhost.pp index 8117e05e4..2db0eebb5 100644 --- a/manifests/resource/vhost.pp +++ b/manifests/resource/vhost.pp @@ -230,7 +230,7 @@ fastcgi_script => $fastcgi_script, try_files => $try_files, www_root => $www_root, - index_files => $index_files, + index_files => undef, location_custom_cfg => $location_custom_cfg, notify => Class['nginx::service'], } diff --git a/templates/vhost/vhost_header.erb b/templates/vhost/vhost_header.erb index 231160d52..b25fd42f9 100644 --- a/templates/vhost/vhost_header.erb +++ b/templates/vhost/vhost_header.erb @@ -31,6 +31,9 @@ server { return 301 https://$host$request_uri; } <% end -%> +<% if @index_files -%> + index <% @index_files.each do |i| %> <%= i %><% end %>; +<% end -%> access_log <%= @access_log_real %>; error_log <%= @error_log_real %>; diff --git a/templates/vhost/vhost_ssl_header.erb b/templates/vhost/vhost_ssl_header.erb index 213b2c559..b1c68c229 100644 --- a/templates/vhost/vhost_ssl_header.erb +++ b/templates/vhost/vhost_ssl_header.erb @@ -20,6 +20,9 @@ server { <% if defined? @auth_basic_user_file -%> auth_basic_user_file "<%= @auth_basic_user_file %>"; <% end -%> +<% if @index_files -%> + index <% @index_files.each do |i| %> <%= i %><% end %>; +<% end -%> access_log <%= @ssl_access_log %>; error_log <%= @ssl_error_log %>; From f338f304c5959bcd34e088ad45eb97560f5d442f Mon Sep 17 00:00:00 2001 From: Daniel Black <daniel.black@openquery.com> Date: Thu, 19 Dec 2013 15:51:59 +1000 Subject: [PATCH 2/2] Force index_files to Array before iteration in templates --- templates/vhost/vhost_header.erb | 2 +- templates/vhost/vhost_location_directory.erb | 2 +- templates/vhost/vhost_ssl_header.erb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/vhost/vhost_header.erb b/templates/vhost/vhost_header.erb index b25fd42f9..fb212fc2e 100644 --- a/templates/vhost/vhost_header.erb +++ b/templates/vhost/vhost_header.erb @@ -32,7 +32,7 @@ server { } <% end -%> <% if @index_files -%> - index <% @index_files.each do |i| %> <%= i %><% end %>; + index <% Array(index_files).each do |i| %> <%= i %><% end %>; <% end -%> access_log <%= @access_log_real %>; diff --git a/templates/vhost/vhost_location_directory.erb b/templates/vhost/vhost_location_directory.erb index ce30782bb..785e16d11 100644 --- a/templates/vhost/vhost_location_directory.erb +++ b/templates/vhost/vhost_location_directory.erb @@ -18,7 +18,7 @@ autoindex on; <% end -%> <% if @index_files -%> - index <% @index_files.each do |i| %> <%= i %><% end %>; + index <% Array(index_files).each do |i| %> <%= i %><% end %>; <% end -%> <% if defined? @auth_basic -%> auth_basic "<%= @auth_basic %>"; diff --git a/templates/vhost/vhost_ssl_header.erb b/templates/vhost/vhost_ssl_header.erb index b1c68c229..3da871184 100644 --- a/templates/vhost/vhost_ssl_header.erb +++ b/templates/vhost/vhost_ssl_header.erb @@ -21,7 +21,7 @@ server { auth_basic_user_file "<%= @auth_basic_user_file %>"; <% end -%> <% if @index_files -%> - index <% @index_files.each do |i| %> <%= i %><% end %>; + index <% Array(index_files).each do |i| %> <%= i %><% end %>; <% end -%> access_log <%= @ssl_access_log %>;