Last active
October 4, 2019 10:14
-
-
Save Sauraus/11060403 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Cookbook Name:: wrapper-nginx | |
# Attributes:: default | |
# | |
default['nginx']['openssl_source']['version'] = '1.0.1g' | |
default['nginx']['default_site_enabled'] = false | |
default['nginx']['disable_access_log'] = true | |
default['nginx']['gzip'] = 'on' | |
default['nginx']['default_root'] = '/wrapper/nginx/www' | |
default['nginx']['log_dir'] = '/wrapper/nginx/log' | |
default['nginx']['user'] = 'nginx' | |
default['nginx']['group'] = 'nginx' | |
#Hash of all websites to create with a config array like this: name => [port, autoindex] | |
default['wrapper-nginx']['sites'] = {:prod => [80, false]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Cookbook Name:: wrapper-nginx | |
# Definition:: wrapper_site | |
# | |
define :wrapper_site do | |
directory "#{node['nginx']['default_root']}/#{params[:name]}" do | |
owner node['nginx']['user'] | |
group node['nginx']['group'] | |
mode 0755 | |
recursive true | |
action :create | |
end | |
directory "#{node['nginx']['log_dir']}/#{params[:name]}" do | |
owner node['nginx']['user'] | |
group node['nginx']['group'] | |
mode 0755 | |
recursive true | |
action :create | |
end | |
template "#{node['nginx']['dir']}/sites-available/#{params[:name]}" do | |
source 'wrapper_site.erb' | |
owner 'root' | |
group 'root' | |
mode '0644' | |
notifies :reload, 'service[nginx]' | |
variables ({:site => params[:name], :port => params[:port], :autoindex => params[:autoindex]}) | |
end | |
nginx_site(params[:name]) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Cookbook Name:: wrapper-nginx | |
# Recipe:: default | |
# | |
user node['nginx']['user'] do | |
system true | |
action :create | |
end | |
include_recipe 'nginx::source' | |
node['wrapper-nginx']['sites'].each do |site, config| | |
wrapper_site(site) do | |
port config[0] | |
autoindex config[1] | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen <%= @port %>; | |
server_name <%= node['hostname'] %>; | |
access_log <%= node['nginx']['log_dir'] %>/<%= @site %>/localhost.access.log; | |
location / { | |
root <%= node['nginx']['default_root'] %>/<%= @site %>; | |
index index.html index.htm; | |
<% if @autoindex == true %> | |
autoindex on; | |
<% end %> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment