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..1254aaa 100644 --- a/manifests/resource/vhost.pp +++ b/manifests/resource/vhost.pp @@ -22,6 +22,8 @@ # [*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 +# [*server_name*] - Virtual host server name. +# [*server_aliases*] - Additional virtual host names, also commonly referred to as server aliases. # # Actions: # @@ -47,6 +49,7 @@ $ipv6_listen_port = '80', $default_server = false, $server_name = $name, + $server_aliases = '', $ssl = absent, $ssl_only = false, $ssl_cert = undef, @@ -56,6 +59,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 +75,9 @@ $create_www_root = false, $owner = '', $groupowner = '', - $fastcgi = absent + $fastcgi = absent, + $auth_basic = undef, + $auth_basic_user_file = undef ) { File { @@ -98,6 +104,15 @@ default => $groupowner, } + # convert server_aliases to an array + $array_server_aliases = is_array($server_aliases) ? { + false => $server_aliases ? { + '' => [], + default => [$server_aliases], + }, + default => $server_aliases, + } + $file_real = "${nginx::vdir}/${name}.conf" # Some OS specific settings: @@ -150,6 +165,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 +175,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/manifests/vhost.pp b/manifests/vhost.pp index 1fb72ee..13c5c7b 100644 --- a/manifests/vhost.pp +++ b/manifests/vhost.pp @@ -7,7 +7,7 @@ # - The $docroot provides the Documentation Root variable # - The $template option specifies whether to use the default template or override # - The $priority of the site -# - The $serveraliases of the site +# - The $server_aliases of the site # # Actions: # - Install Nginx Virtual Hosts @@ -27,7 +27,8 @@ $port = '80', $template = 'nginx/vhost/vhost.conf.erb', $priority = '50', - $serveraliases = '', + $serveraliases = undef, + $server aliases = '', $create_docroot = true, $enable = true, $owner = '', @@ -49,6 +50,20 @@ $bool_create_docroot = any2bool($create_docroot) + # $serveraliases is deprecated + if ($serveraliases != undef) { + warning('nginx: nginx::vhost serveraliases is deprecated. Please use server_aliases instead.') + } + + # convert server_aliases to an array + $array_server_aliases = is_array($server_aliases) ? { + false => $server_aliases ? { + '' => [], + default => [$server_aliases], + }, + default => $server_aliases, + } + file { "${nginx::vdir}/${priority}-${name}.conf": content => template($template), mode => $nginx::config_file_mode, 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_header.erb b/templates/vhost/vhost_header.erb index 4d7667b..2b0a7aa 100644 --- a/templates/vhost/vhost_header.erb +++ b/templates/vhost/vhost_header.erb @@ -2,7 +2,7 @@ server { listen <%= @listen_ip %><% if defined? @listen_port %>:<%= @listen_port %><% end %><% if @bool_default_server %> default_server<% end %>; <% # check to see if ipv6 support exists in the kernel before applying %> <% if @bool_ipv6_enable && (defined? @ipaddress6) %>listen [<%= @ipv6_listen_ip %>]:<%= @ipv6_listen_port %> default ipv6only=on;<% end %> - server_name <%= @server_name %>; + server_name <%= @server_name %> <%= Array(@array_server_aliases).join(' ') %>; access_log <%= scope.lookupvar('nginx::log_dir')%>/<%= @name %>.access.log; <% if (defined? @www_root) %> 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 %>; diff --git a/templates/vhost/vhost_ssl_header.erb b/templates/vhost/vhost_ssl_header.erb index 3fb58fa..caabe9e 100644 --- a/templates/vhost/vhost_ssl_header.erb +++ b/templates/vhost/vhost_ssl_header.erb @@ -1,7 +1,7 @@ server { listen <%= @ssl_listen_ip %>:<%= @ssl_listen_port %><% if @bool_default_server %> default_server<% end %>; <% if @bool_ipv6_enable && (defined? @ipaddress6) %>listen [<%= @ipv6_listen_ip %>]:<%= @ipv6_listen_port %> default ipv6only=on;<% end %> - server_name <%= @server_name %>; + server_name <%= @server_name %> <%= Array(@array_server_aliases).join(' ') %>; access_log <%= scope.lookupvar('nginx::log_dir')%>/<%= @name %>.access.log; ssl on;