diff --git a/manifests/resource/location.pp b/manifests/resource/location.pp index c8b0701..caa9eb1 100644 --- a/manifests/resource/location.pp +++ b/manifests/resource/location.pp @@ -39,6 +39,7 @@ $auth_basic = undef, $www_root = undef, $create_www_root = false, + $alias_path = undef, $owner = '', $groupowner = '', $redirect = undef, @@ -47,6 +48,7 @@ $proxy_read_timeout = '90', $proxy_set_header = ['Host $host', 'X-Real-IP $remote_addr', 'X-Forwarded-For $proxy_add_x_forwarded_for', 'X-Forwarded-Proto $scheme' ], $proxy_redirect = undef, + $proxy_http_version = undef, $ssl = false, $ssl_only = false, $option = undef, @@ -99,21 +101,23 @@ } ## Check for various error condtiions + # Check vhost if ($vhost == undef) { fail('Cannot create a location reference without attaching to a virtual host') } - if (($www_root == undef) and ($proxy == undef) and ($redirect == undef)) { - fail('Cannot create a location reference without a www_root, proxy or redirect defined') + # Check www_root/proxy/redirect/alias_path + if (($www_root == undef) and ($proxy == undef) and ($redirect == undef) and ($alias_path == undef)) { + fail('Cannot create a location reference without a www_root, proxy, redirect, or alias_path defined') } - if (($www_root != undef) and ($proxy != undef)) { - fail('Cannot define both directory and proxy in a virtual host') - } - if (($www_root != undef) and ($redirect != undef)) { - fail('Cannot define both directory and redirect in a virtual host') - } - if (($proxy != undef) and ($redirect != undef)) { - fail('Cannot define both proxy and redirect in a virtual host') + + $mutual_exclusive = [$www_root, $proxy, $redirect, $alias_path] + + # count all values which are not nil/undef - must be 1 + if (count($mutual_exclusive) != 1) { + fail("Cannot define more than one of the following values: www_root: '$www_root', redirect: '$redirect', proxy: '$proxy', and alias_path: '$alias_path'!") } + + # Check auth if (($auth_basic_user_file != undef) and ($auth_basic == undef)) { fail('Cannot define auth_basic_user_file without auth_basic') } diff --git a/manifests/resource/vhost.pp b/manifests/resource/vhost.pp index 5916bb1..837a95c 100644 --- a/manifests/resource/vhost.pp +++ b/manifests/resource/vhost.pp @@ -56,6 +56,7 @@ $proxy = undef, $proxy_read_timeout = '90', $proxy_set_header = undef, + $proxy_http_version = undef, $proxy_redirect = undef, $redirect = undef, $index_files = ['index.html', 'index.htm', 'index.php'], @@ -71,7 +72,9 @@ $create_www_root = false, $owner = '', $groupowner = '', - $fastcgi = absent + $fastcgi = absent, + $auth_basic = undef, + $auth_basic_user_file = undef ) { File { @@ -150,6 +153,7 @@ proxy_read_timeout => $proxy_read_timeout, proxy_set_header => $proxy_set_header, proxy_redirect => $proxy_redirect, + proxy_http_version => $proxy_http_version, redirect => $redirect, www_root => $www_root, create_www_root => $create_www_root, @@ -159,6 +163,8 @@ template_proxy => $template_proxy, template_ssl_proxy => $template_ssl_proxy, template_directory => $template_directory, + auth_basic => $auth_basic, + auth_basic_user_file => $auth_basic_user_file, } # Use the File Fragment Pattern to construct the configuration files. diff --git a/templates/conf.d/proxy.conf.erb b/templates/conf.d/proxy.conf.erb index 677e2d3..05cfcc8 100644 --- a/templates/conf.d/proxy.conf.erb +++ b/templates/conf.d/proxy.conf.erb @@ -8,3 +8,4 @@ proxy_buffers <%= scope.lookupvar('nginx::params::nx_proxy_buffers') % <% scope.lookupvar('nginx::params::nx_proxy_set_header').each do |header| %> proxy_set_header <%= header %>; <% end %> +<% unless @nx_proxy_http_version.nil? || @nx_proxy_http_version.empty? -%>proxy_http_version <%= scope.lookupvar('nginx::params::nx_proxy_http_version') %>;<% end %> diff --git a/templates/vhost/vhost_location_directory.erb b/templates/vhost/vhost_location_directory.erb index bc84439..10d77d7 100644 --- a/templates/vhost/vhost_location_directory.erb +++ b/templates/vhost/vhost_location_directory.erb @@ -1,5 +1,10 @@ location <%= @location %> { +<% unless @www_root.nil? || @www_root.empty? -%> root <%= @www_root %>; +<% end -%> +<% unless @alias_path.nil? || @alias_path.empty? -%> + alias <%= @alias_path %>; +<% end -%> index <% @index_files.each do |i| %> <%= i %> <% end %>; <% unless @auth_basic.nil? || @auth_basic.empty? -%> auth_basic <%= @auth_basic %>; diff --git a/templates/vhost/vhost_location_proxy.erb b/templates/vhost/vhost_location_proxy.erb index f9d153b..a7cd9cb 100644 --- a/templates/vhost/vhost_location_proxy.erb +++ b/templates/vhost/vhost_location_proxy.erb @@ -4,6 +4,9 @@ <% unless @proxy_redirect.nil? || @proxy_redirect.empty? -%> proxy_redirect <%= @proxy_redirect %>; <% end -%> +<% unless @proxy_http_version.nil? || @proxy_http_version.empty? -%> + proxy_http_version <%= @proxy_http_version %>; +<% end %> <% unless @proxy_set_header.nil? || @proxy_set_header.empty? -%> <% @proxy_set_header.each do |header| -%> proxy_set_header <%= header %>;