2019-03-03 08:50:49 +00:00
|
|
|
# Create the necessary directories:
|
|
|
|
%w( body fastcgi proxy scgi uwsgi ).each do |d|
|
|
|
|
directory "/var/lib/nginx/#{d}" do
|
|
|
|
owner 'www-data'
|
|
|
|
group 'root'
|
|
|
|
mode '755'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-27 06:48:30 +00:00
|
|
|
%w( sites-available sites-enabled stream-available stream-enabled).each do |d|
|
2019-03-03 08:50:49 +00:00
|
|
|
directory "/etc/nginx/#{d}" do
|
|
|
|
owner 'root'
|
|
|
|
group 'root'
|
|
|
|
mode '755'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Deploy the nginx configuration files:
|
|
|
|
remote_file '/etc/nginx/nginx.conf' do
|
|
|
|
owner 'root'
|
|
|
|
group 'root'
|
|
|
|
mode '644'
|
2019-10-27 06:48:30 +00:00
|
|
|
|
2019-03-03 08:50:49 +00:00
|
|
|
notifies :reload, 'service[nginx]'
|
|
|
|
end
|
|
|
|
|
|
|
|
%w( default maintenance ).each do |conf|
|
|
|
|
remote_file "/etc/nginx/sites-available/#{conf}" do
|
|
|
|
owner 'root'
|
|
|
|
group 'root'
|
|
|
|
mode '644'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
link '/etc/nginx/sites-enabled/default' do
|
|
|
|
to '/etc/nginx/sites-available/default'
|
|
|
|
|
|
|
|
notifies :reload, 'service[nginx]'
|
|
|
|
end
|
|
|
|
|
|
|
|
# Log rotation setting:
|
|
|
|
remote_file '/etc/logrotate.d/nginx' do
|
|
|
|
owner 'root'
|
|
|
|
group 'root'
|
|
|
|
mode '644'
|
|
|
|
end
|
|
|
|
|
|
|
|
# Deploy the systemd file:
|
|
|
|
remote_file '/lib/systemd/system/nginx.service' do
|
|
|
|
owner 'root'
|
|
|
|
group 'root'
|
|
|
|
mode '644'
|
|
|
|
end
|
|
|
|
|
|
|
|
# Firewall Setting:
|
|
|
|
%w( 80/tcp 443/tcp ).each do |port|
|
|
|
|
execute "ufw allow #{port}" do
|
|
|
|
user 'root'
|
|
|
|
|
|
|
|
not_if "LANG=c ufw status | grep #{port}"
|
|
|
|
|
|
|
|
notifies :run, 'execute[ufw reload-or-enable]'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
execute 'ufw reload-or-enable' do
|
|
|
|
user 'root'
|
|
|
|
command 'LANG=C ufw reload | grep skipping && ufw --force enable || exit 0'
|
|
|
|
|
|
|
|
action :nothing
|
|
|
|
end
|
|
|
|
|
|
|
|
# Service setting:
|
|
|
|
service 'nginx' do
|
|
|
|
action [ :enable, :start ]
|
|
|
|
end
|