diff --git a/manifests/resource/server.pp b/manifests/resource/server.pp index c6497642f..0fe501901 100644 --- a/manifests/resource/server.pp +++ b/manifests/resource/server.pp @@ -200,7 +200,7 @@ Optional[String] $uwsgi = undef, Optional[String] $uwsgi_params = "${nginx::config::conf_dir}/uwsgi_params", Optional[String] $uwsgi_read_timeout = undef, - Array $index_files = [ + Optional[Array] $index_files = [ 'index.html', 'index.htm', 'index.php'], diff --git a/spec/defines/resource_server_spec.rb b/spec/defines/resource_server_spec.rb index 2ce119d84..02c2c3232 100644 --- a/spec/defines/resource_server_spec.rb +++ b/spec/defines/resource_server_spec.rb @@ -317,6 +317,18 @@ attr: 'error_pages', value: { '503' => '/foo.html' }, match: ' error_page 503 /foo.html;' + }, + { + title: 'should set index_file(s)', + attr: 'index_files', + value: %w(name1 name2), + match: %r{\s*index\s+name1\s+name2;} + }, + { + title: 'should not set index_file(s)', + attr: 'index_files', + value: :undef, + match: %r{^((?!index).)*$} } ].each do |param| context "when #{param[:attr]} is #{param[:value]}" do @@ -733,6 +745,18 @@ attr: 'use_default_location', value: true, notmatch: %r{ root /;} + }, + { + title: 'should set index_file(s)', + attr: 'index_files', + value: %w(name1 name2), + match: %r{\s*index\s+name1\s+name2;} + }, + { + title: 'should not set index_file(s)', + attr: 'index_files', + value: :undef, + match: %r{^((?!index).)*$} } ].each do |param| context "when #{param[:attr]} is #{param[:value]}" do diff --git a/templates/server/server_header.erb b/templates/server/server_header.erb index f4f91f985..0d26c3baf 100644 --- a/templates/server/server_header.erb +++ b/templates/server/server_header.erb @@ -145,7 +145,7 @@ server { <% if @ssl_redirect -%> return 301 https://$host<% if @_ssl_redirect_port.to_i != 443 %>:<%= @_ssl_redirect_port %><% end %>$request_uri; <% end -%> -<% if @index_files.count > 0 and not @ssl_only -%> +<% if @index_files and @index_files.count > 0 and not @ssl_only -%> index <% Array(@index_files).each do |i| %> <%= i %><% end %>; <% end -%> diff --git a/templates/server/server_ssl_header.erb b/templates/server/server_ssl_header.erb index e02838689..dc645de1e 100644 --- a/templates/server/server_ssl_header.erb +++ b/templates/server/server_ssl_header.erb @@ -81,7 +81,7 @@ server { <% if defined? @gzip_types -%> gzip_types <%= @gzip_types %>; <% end -%> -<% if @index_files.count > 0 -%> +<% if @index_files and @index_files.count > 0 -%> index <% Array(@index_files).each do |i| %> <%= i %><% end %>; <% end -%>