Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iterate server_name when rewrite_www_to_non_www is used #683

Merged
merged 2 commits into from
Sep 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions spec/defines/resource_vhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,8 @@
}
end

it "should set the server_name of the rewrite server stanza to the first server_name with 'www.' stripped" do
is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(/^\s+server_name\s+foo.com;/)
it "should set the server_name of the rewrite server stanza to every server_name with 'www.' stripped" do
is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(/^\s+server_name\s+foo.com\s+bar.foo.com\s+foo.com;/)
end
end

Expand All @@ -726,8 +726,8 @@
}
end

it "should set the server_name of the rewrite server stanza to the first server_name with 'www.' stripped" do
is_expected.to contain_concat__fragment("#{title}-header").with_content(/^\s+server_name\s+foo.com;/)
it "should set the server_name of the rewrite server stanza to every server_name with 'www.' stripped" do
is_expected.to contain_concat__fragment("#{title}-header").with_content(/^\s+server_name\s+foo.com\s+bar.foo.com\s+foo.com;/)
end
end

Expand Down
8 changes: 5 additions & 3 deletions templates/vhost/vhost_header.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<% if @rewrite_www_to_non_www -%>
<%- @server_name.each do |s| -%>
server {
<%- if @listen_ip.is_a?(Array) then -%>
<%- @listen_ip.each do |ip| -%>
Expand All @@ -17,10 +18,11 @@ server {
listen [<%= @ipv6_listen_ip %>]:<%= @ipv6_listen_port %> <% if @ipv6_listen_options %><%= @ipv6_listen_options %><% end %>;
<%- end -%>
<%- end -%>
server_name www.<%= @server_name[0].gsub(/^www\./, '') %>;
return 301 http://<%= @server_name[0].gsub(/^www\./, '') %>$request_uri;
server_name www.<%= s.gsub(/^www\./, '') %>;
return 301 http://<%= s.gsub(/^www\./, '') %>$request_uri;
}

<% end -%>
<% end -%>
server {
<%- if @listen_ip.is_a?(Array) then -%>
Expand All @@ -40,7 +42,7 @@ server {
listen [<%= @ipv6_listen_ip %>]:<%= @ipv6_listen_port %> <% if @ipv6_listen_options %><%= @ipv6_listen_options %><% end %>;
<%- end -%>
<%- end -%>
server_name <%= @rewrite_www_to_non_www ? @server_name[0].gsub(/^www\./, '') : @server_name.join(" ") %>;
server_name <%= @rewrite_www_to_non_www ? @server_name.join(" ").gsub(/(^| )(www\.)?(?=[a-z0-9])/, '') : @server_name.join(" ") %>;
<%- if instance_variables.any? { |iv| iv.to_s.include? 'auth_basic' } -%>
<%- if defined? @auth_basic -%>
auth_basic "<%= @auth_basic %>";
Expand Down
8 changes: 5 additions & 3 deletions templates/vhost/vhost_ssl_header.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<% if @rewrite_www_to_non_www -%>
<%- @server_name.each do |s| -%>
server {
<%- if @listen_ip.is_a?(Array) then -%>
<%- @listen_ip.each do |ip| -%>
Expand All @@ -17,13 +18,14 @@ server {
listen [<%= @ipv6_listen_ip %>]:<%= @ssl_port %> ssl<% if @spdy == 'on' %> spdy<% end %><% if @ipv6_listen_options %> <%= @ipv6_listen_options %><% end %>;
<%- end -%>
<%- end -%>
server_name www.<%= @server_name[0].gsub(/^www\./, '') %>;
return 301 https://<%= @server_name[0].gsub(/^www\./, '') %>$request_uri;
server_name www.<%= s.gsub(/^www\./, '') %>;
return 301 https://<%= s.gsub(/^www\./, '') %>$request_uri;

<%= scope.function_template(["nginx/vhost/vhost_ssl_settings.erb"]) %>

}

<% end -%>
<% end -%>
server {
<%- if @listen_ip.is_a?(Array) then -%>
Expand All @@ -43,7 +45,7 @@ server {
listen [<%= @ipv6_listen_ip %>]:<%= @ssl_port %> ssl<% if @spdy == 'on' %> spdy<% end %><% if @ipv6_listen_options %> <%= @ipv6_listen_options %><% end %>;
<%- end -%>
<%- end -%>
server_name <%= @rewrite_www_to_non_www ? @server_name[0].gsub(/^www\./, '') : @server_name.join(" ") %>;
server_name <%= @rewrite_www_to_non_www ? @server_name.join(" ").gsub(/(^| )(www\.)?(?=[a-z0-9])/, '') : @server_name.join(" ") %>;

<%= scope.function_template(["nginx/vhost/vhost_ssl_settings.erb"]) %>

Expand Down