2019-04-12 23:32:53 +02:00
|
|
|
# Set defaults, use debian as base
|
|
|
|
|
|
|
|
server_available = '/etc/nginx/sites-available'
|
|
|
|
server_enabled = '/etc/nginx/sites-enabled'
|
|
|
|
|
2021-02-14 09:22:55 +01:00
|
|
|
# Override by platform family
|
|
|
|
case platform[:family]
|
|
|
|
when 'redhat','fedora'
|
2019-04-12 23:32:53 +02:00
|
|
|
server_available = '/etc/nginx/conf.d'
|
|
|
|
server_enabled = '/etc/nginx/conf.d'
|
2021-02-14 09:22:55 +01:00
|
|
|
when 'suse'
|
2019-04-13 20:49:35 +02:00
|
|
|
server_available = '/etc/nginx/vhosts.d'
|
|
|
|
server_enabled = '/etc/nginx/vhosts.d'
|
2019-04-12 23:32:53 +02:00
|
|
|
end
|
|
|
|
|
2019-04-12 17:34:35 +02:00
|
|
|
control 'Nginx configuration' do
|
|
|
|
title 'should match desired lines'
|
|
|
|
|
2019-04-12 23:32:53 +02:00
|
|
|
# main configuration
|
2019-04-12 17:34:35 +02:00
|
|
|
describe file('/etc/nginx/nginx.conf') do
|
|
|
|
it { should be_file }
|
|
|
|
it { should be_owned_by 'root' }
|
|
|
|
it { should be_grouped_into 'root' }
|
|
|
|
its('mode') { should cmp '0644' }
|
2019-04-26 17:11:51 +02:00
|
|
|
its('content') { should include %Q[ log_format main '$remote_addr - $remote_user [$time_local] $status '
|
|
|
|
'"$request" $body_bytes_sent "$http_referer" '
|
|
|
|
'"$http_user_agent" "$http_x_forwarded_for"';] }
|
2019-04-12 17:34:35 +02:00
|
|
|
end
|
2019-04-12 23:32:53 +02:00
|
|
|
|
|
|
|
# snippets configuration
|
|
|
|
describe file('/etc/nginx/snippets/letsencrypt.conf') do
|
|
|
|
it { should be_file }
|
|
|
|
it { should be_owned_by 'root' }
|
|
|
|
it { should be_grouped_into 'root' }
|
|
|
|
its('mode') { should cmp '0644' }
|
|
|
|
its('content') { should include 'location ^~ /.well-known/acme-challenge/ {' }
|
|
|
|
its('content') { should include 'proxy_pass http://localhost:9999;' }
|
|
|
|
its('content') { should include '{' }
|
|
|
|
end
|
|
|
|
|
|
|
|
# sites configuration
|
|
|
|
[server_available, server_enabled].each do |dir|
|
|
|
|
|
|
|
|
describe file ("#{dir}/default") do
|
|
|
|
it { should_not exist }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe file ("#{dir}/mysite") do
|
|
|
|
it { should be_file }
|
|
|
|
it { should be_owned_by 'root' }
|
|
|
|
it { should be_grouped_into 'root' }
|
|
|
|
its('mode') { should cmp '0644' }
|
|
|
|
its('content') { should include 'server_name localhost;' }
|
|
|
|
its('content') { should include 'listen 80 default_server;' }
|
|
|
|
its('content') { should include 'index index.html index.htm;' }
|
|
|
|
its('content') { should include 'location ~ .htm {' }
|
|
|
|
its('content') { should include 'try_files $uri $uri/ =404;' }
|
|
|
|
its('content') { should include 'include snippets/letsencrypt.conf;' }
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2019-04-12 17:34:35 +02:00
|
|
|
end
|