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

Add access and error logs directives when www_to_non_www or non_www_to_www is used #1546

Merged
merged 2 commits into from
Jun 28, 2023
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
24 changes: 24 additions & 0 deletions spec/defines/resource_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@

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+return\s+301\s+http://rspec\.example\.com\$request_uri;\n
\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}x
},
{
title: 'should not contain www to non-www rewrite',
attr: 'rewrite_www_to_non_www',
Expand Down Expand Up @@ -418,6 +426,14 @@
let(:title) { 'rspec.example.com' }

[
{
title: 'should contain access and error logs directives inside the non-www rewrite',
attr: 'rewrite_non_www_to_www',
value: true,
match: %r{\s+return\s+301\s+http://www.rspec\.example\.com\$request_uri;\n
\s+access_log\s+/var/log/nginx/rspec.example.com.access.log;\n
\s+error_log\s+/var/log/nginx/rspec.example.com.error.log;\n}x
},
{
title: 'should not contain non-www to www rewrite',
attr: 'rewrite_non_www_to_www',
Expand Down Expand Up @@ -477,6 +493,14 @@
let(:title) { 'rspec.example.com' }

[
{
title: 'should contain access and error logs directives inside the non-www rewrite',
attr: 'rewrite_non_www_to_www',
value: true,
match: %r{\s+return\s+301\s+https://www.rspec\.example\.com\$request_uri;\n
\s+access_log\s+/var/log/nginx/ssl-rspec.example.com.access.log;\n
\s+error_log\s+/var/log/nginx/ssl-rspec.example.com.error.log;\n}x
},
{
title: 'should not contain non-www to www rewrite',
attr: 'rewrite_non_www_to_www',
Expand Down Expand Up @@ -1404,7 +1428,7 @@

# TODO: implement test after this can be tested
# msg = %r{nginx: ssl must be true if listen_port is the same as ssl_port}
it 'Testing for warnings not yet implemented in classes'

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

nginx::resource::server on virtuozzolinux-7-x86_64 with Facter 3.14.5 and Puppet 8.1.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

nginx::resource::server on almalinux-8-x86_64 with Facter 4.2.5 and Puppet 8.1.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

nginx::resource::server on almalinux-9-x86_64 with Facter 4.2.10 and Puppet 8.1.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

nginx::resource::server on archlinux-rolling-x86_64 with Facter 4.2.9 and Puppet 8.1.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

nginx::resource::server on centos-7-x86_64 with Facter 4.2.2 and Puppet 8.1.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

nginx::resource::server on centos-8-x86_64 with Facter 4.2.2 and Puppet 8.1.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

nginx::resource::server on centos-9-x86_64 with Facter 4.2.2 and Puppet 8.1.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

nginx::resource::server on debian-10-x86_64 with Facter 4.2.2 and Puppet 8.1.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

nginx::resource::server on debian-11-x86_64 with Facter 4.2.5 and Puppet 8.1.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

nginx::resource::server on redhat-7-x86_64 with Facter 4.2.13 and Puppet 8.1.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

nginx::resource::server on virtuozzolinux-7-x86_64 with Facter 3.14.5 and Puppet 7.25.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

nginx::resource::server on ubuntu-20.04-x86_64 with Facter 4.2.5 and Puppet 7.25.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

nginx::resource::server on rocky-8-x86_64 with Facter 4.2.5 and Puppet 7.25.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

nginx::resource::server on centos-9-x86_64 with Facter 4.2.2 and Puppet 7.25.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

nginx::resource::server on sles-12-x86_64 with Facter 4.2.14 and Puppet 7.25.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

nginx::resource::server on debian-10-x86_64 with Facter 4.2.2 and Puppet 7.25.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

nginx::resource::server on redhat-9-x86_64 with Facter 4.2.13 and Puppet 7.25.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

nginx::resource::server on archlinux-rolling-x86_64 with Facter 4.2.9 and Puppet 7.25.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

nginx::resource::server on almalinux-8-x86_64 with Facter 4.2.5 and Puppet 7.25.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented

Check warning on line 1431 in spec/defines/resource_server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

nginx::resource::server on almalinux-9-x86_64 with Facter 4.2.10 and Puppet 7.25.0 os-independent items attribute resources when listen_port == ssl_port but ssl = false Testing for warnings not yet implemented in classes Skipped: Not yet implemented
end

context 'when listen_port != ssl_port' do
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
Loading