Skip to content

Commit

Permalink
Merge pull request #310 from kalmanolah/rewrite_non_www
Browse files Browse the repository at this point in the history
Use first server name for non-www redirects to prevent issues with naming of vhosts within defined types.
  • Loading branch information
James Fryman committed Jun 26, 2014
2 parents 2079706 + 12d515f commit 8203f55
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions templates/vhost/vhost_footer.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ include <%= file %>;
<% if @rewrite_www_to_non_www -%>
server {
listen <%= @listen_ip %>:<%= @listen_port %>;
server_name www.<%= @name.gsub(/^www\./, '') %>;
return 301 http://<%= @name.gsub(/^www\./, '') %>$uri;
server_name www.<%= @server_name[0].gsub(/^www\./, '') %>;
return 301 http://<%= @server_name[0].gsub(/^www\./, '') %>$uri;
}
<% end -%>
2 changes: 1 addition & 1 deletion templates/vhost/vhost_header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ server {
<% if @ipv6_enable && (defined? @ipaddress6) %>
listen [<%= @ipv6_listen_ip %>]:<%= @ipv6_listen_port %> <% if @ipv6_listen_options %><%= @ipv6_listen_options %><% end %>;
<% end %>
server_name <%= @rewrite_www_to_non_www ? @name.gsub(/^www\./, '') : @server_name.join(" ") %>;
server_name <%= @rewrite_www_to_non_www ? @server_name[0].gsub(/^www\./, '') : @server_name.join(" ") %>;
<% if defined? @auth_basic -%>
auth_basic "<%= @auth_basic %>";
<% end -%>
Expand Down
4 changes: 2 additions & 2 deletions templates/vhost/vhost_ssl_footer.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ include <%= file %>;
<% if @rewrite_www_to_non_www -%>
server {
listen <%= @listen_ip %>:<%= @ssl_port %> ssl;
server_name www.<%= @name.gsub(/^www\./, '') %>;
return 301 https://<%= @name.gsub(/^www\./, '') %>$uri;
server_name www.<%= @server_name[0].gsub(/^www\./, '') %>;
return 301 https://<%= @server_name[0].gsub(/^www\./, '') %>$uri;
}
<% end %>
2 changes: 1 addition & 1 deletion templates/vhost/vhost_ssl_header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ server {
<% if @ipv6_enable && (defined? @ipaddress6) %>
listen [<%= @ipv6_listen_ip %>]:<%= @ssl_port %> ssl<% if @spdy == 'on' %> spdy<% end %><% if @ipv6_listen_options %> <%= @ipv6_listen_options %><% end %>;
<% end %>
server_name <%= @rewrite_www_to_non_www ? @name.gsub(/^www\./, '') : @server_name.join(" ") %>;
server_name <%= @rewrite_www_to_non_www ? @server_name[0].gsub(/^www\./, '') : @server_name.join(" ") %>;

ssl on;

Expand Down

0 comments on commit 8203f55

Please sign in to comment.