From 25b1f4b4386cb3d86d982cdfa04fd9bbdaca0230 Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Sun, 27 Mar 2016 03:47:45 +0200 Subject: [PATCH] Add rewrite_to_https_port setting support --- manifests/resource/vhost.pp | 9 +++++++++ templates/vhost/vhost_header.erb | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/manifests/resource/vhost.pp b/manifests/resource/vhost.pp index ad37a095b..c2f6f1603 100644 --- a/manifests/resource/vhost.pp +++ b/manifests/resource/vhost.pp @@ -135,6 +135,8 @@ # put before everything else inside vhost ssl # [*rewrite_to_https*] - Adds a server directive and rewrite rule to # rewrite to ssl +# [*rewrite_to_https_port*] - Add https port to rewrite. Useful, when nginx +# SSL is behind port multiplexer. Default to 8443 # [*include_files*] - Adds include files to vhost # [*access_log*] - Where to write access log. May add additional # options like log format to the end. @@ -235,6 +237,7 @@ $www_root = undef, $rewrite_www_to_non_www = false, $rewrite_to_https = undef, + $rewrite_to_https_port = 8443, $location_custom_cfg = undef, $location_cfg_prepend = undef, $location_cfg_append = undef, @@ -411,6 +414,12 @@ if ($rewrite_to_https != undef) { validate_bool($rewrite_to_https) } + if is_string($rewrite_to_https_port) { + warning('DEPRECATION: String $rewrite_to_https_port must be converted to an integer. Integer string support will be removed in a future release.') + } + elsif !is_integer($rewrite_to_https_port) { + fail('$rewrite_to_https_port must be an integer.') + } if ($raw_prepend != undef) { if (is_array($raw_prepend)) { validate_array($raw_prepend) diff --git a/templates/vhost/vhost_header.erb b/templates/vhost/vhost_header.erb index cf26c3f9f..be412ea69 100644 --- a/templates/vhost/vhost_header.erb +++ b/templates/vhost/vhost_header.erb @@ -136,7 +136,7 @@ server { <% end -%> <% if @rewrite_to_https -%> if ($ssl_protocol = "") { - return 301 https://$host<% if @ssl_port.to_i != 443 %>:<%= @ssl_port %><% end %>$request_uri; + return 301 https://$host<% if @rewrite_to_https_port %><% if @rewrite_to_https_port.to_i != 443 %>:<%= @rewrite_to_https_port %><% end %><% elsif @ssl_port.to_i != 443 %>:<%= @ssl_port %><% end %>$request_uri; } <% end -%> <% if @index_files.count > 0 -%>