Skip to content

Instantly share code, notes, and snippets.

@piotrze
Last active September 6, 2016 11:23
Show Gist options
  • Save piotrze/5e67fd96e621a6d10aeb to your computer and use it in GitHub Desktop.
Save piotrze/5e67fd96e621a6d10aeb to your computer and use it in GitHub Desktop.
Setup CORS on engineyard for font files(fontawesome)
#nginx_cors/recipes/default.rb
#create new directory in cookbooks/ in your ey-cloud-recipes repository
#upload recipie, apply and restart nginx on all servers
#
# Cookbook Name:: nginx_cors
# Recipe:: default
#
if ['app_master', 'app', 'solo'].include?(node[:instance_role])
node[:applications].each do |app, data|
template "/tmp/location.block" do
source 'location.block.erb'
end
execute "add header to conf" do
command "sed -i '/error_log \\/var\\/log\\/engineyard\\/nginx\\/#{app}.error.log notice;/r /tmp/location.block' /etc/nginx/servers/#{app}.conf"
not_if "grep -q Access-Control-Allow-Origin /etc/nginx/servers/#{app}.conf"
end
end
end
#nginx_cors/templates/default/location.block.erb
location ~ ^/(assets|stylesheets)/ {
if ($request_filename ~ (ttf|ttc|otf|eot|woff)$) {
add_header Access-Control-Allow-Origin *;
}
}
@bmishkin
Copy link

bmishkin commented Sep 6, 2016

thanks for the script!

after using for awhile, I added

    execute "reload-nginx" do
      action :nothing
      command "/etc/init.d/nginx reload"
    end

    execute "add header to conf" do
      ...
      notifies :run, resources(:execute => "reload-nginx")

to ensure that nginx was reloaded. It appeared on my systems that nginx was starting before the .conf file was updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment