Skip to content

Instantly share code, notes, and snippets.

@dipth
Created May 26, 2014 14:56
Show Gist options
  • Save dipth/7359e736fcebf34f1b00 to your computer and use it in GitHub Desktop.
Save dipth/7359e736fcebf34f1b00 to your computer and use it in GitHub Desktop.
Customize nginx config recipe
location ~* \.(eot|ttf|woff)$ {
add_header Access-Control-Allow-Origin *;
}
#
# Cookbook Name:: customize_nginx
# Recipe:: default
#
if ["app", "app_master", "solo"].include?(node[:instance_role])
node[:applications].each do |app_name, data|
remote_file "/etc/nginx/servers/#{app_name}/assets_cors.conf" do
source "assets_cors.conf"
mode 0644
owner node[:owner_name]
group node[:owner_name]
backup false
action :create
end
ruby_block "include assets_cors.conf" do
block do
# Read default custom config
contents = File.read("/etc/nginx/servers/#{app_name}/custom.conf")
# Append include if not already included
unless contents =~ /assets_cors\.conf/
contents += "\ninclude /etc/nginx/servers/#{app_name}/assets_cors.conf;"
end
# Save custom unicorn config
File.write("/etc/nginx/servers/#{app_name}/custom.conf", contents.strip, :mode => 'w')
end
only_if { File.exist?("/etc/nginx/servers/#{app_name}/custom.conf") }
end
end
# Restart nginx
execute "Restart nginx" do
command %Q{
/etc/init.d/nginx restart
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment