Skip to content

Commit

Permalink
Add access and error logs directives when www_to_non_www or non_www_t…
Browse files Browse the repository at this point in the history
…o_www is used.
  • Loading branch information
Mike Tiurin committed Jun 27, 2023
1 parent 1cf3b1d commit e6b3482
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
7 changes: 7 additions & 0 deletions spec/defines/resource_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@

describe 'server_header template content' do
[
{
title: 'should contain access and error logs directives inside the www rewrite',
attr: 'rewrite_www_to_non_www',
value: true,
match: %r{\s+access_log\s+/var/log/nginx/www.rspec.example.com.access.log;\n
\s+error_log\s+/var/log/nginx/www.rspec.example.com.error.log;\n}
},
{
title: 'should not contain www to non-www rewrite',
attr: 'rewrite_www_to_non_www',
Expand Down
22 changes: 22 additions & 0 deletions templates/server/server_header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ server {
return 301 http://www.<%= s %>$request_uri;
<%- end -%>
<%- end -%>
<% if @access_log.is_a?(Array) -%>
<%- @access_log.each do |log_item| -%>
access_log <%= log_item %><% if @format_log %> <%= @format_log%><% end %>;
<%- end -%>
<% elsif @access_log == 'absent' -%>
<% elsif @access_log == 'off' -%>
access_log off;
<% elsif not @access_log -%>
access_log <%= scope['::nginx::config::log_dir'] %>/<%= @name_sanitized %>.access.log<% if @format_log %> <%= @format_log%><% end %>;
<% else -%>
access_log <%= @access_log %><% if @format_log %> <%= @format_log%><% end %>;
<% end -%>
<% if @error_log.is_a?(Array) -%>
<%- @error_log.each do |log_item| -%>
error_log <%= log_item %>;
<%- end -%>
<% elsif @error_log == 'absent' -%>
<% elsif not @error_log -%>
error_log <%= scope['::nginx::config::log_dir'] %>/<%= @name_sanitized %>.error.log;
<% else -%>
error_log <%= @error_log %>;
<% end -%>
}

<% end -%>
Expand Down
23 changes: 22 additions & 1 deletion templates/server/server_ssl_header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,28 @@ server {
server_name <%= s.gsub(/^www\./, '') %>;
return 301 https://www.<%= s %>$request_uri;
<%- end -%>
<% if @access_log.is_a?(Array) -%>
<%- @access_log.each do |log_item| -%>
access_log <%= log_item %><% if @format_log %> <%= @format_log%><% end %>;
<%- end -%>
<% elsif @access_log == 'absent' -%>
<% elsif @access_log == 'off' -%>
access_log off;
<% elsif not @access_log -%>
access_log <%= scope['::nginx::config::log_dir'] %>/ssl-<%= @name_sanitized %>.access.log<% if @format_log %> <%= @format_log%><% end %>;
<% else -%>
access_log <%= @access_log %><% if @format_log %> <%= @format_log%><% end %>;
<% end -%>
<% if @error_log.is_a?(Array) -%>
<%- @error_log.each do |log_item| -%>
error_log <%= log_item %>;
<%- end -%>
<% elsif @error_log == 'absent' -%>
<% elsif not @error_log -%>
error_log <%= scope['::nginx::config::log_dir'] %>/ssl-<%= @name_sanitized %>.error.log;
<% else -%>
error_log <%= @error_log %>;
<% end -%>
<%= scope.function_template(["nginx/server/server_ssl_settings.erb"]) %>

}
Expand Down

0 comments on commit e6b3482

Please sign in to comment.