Skip to content

Instantly share code, notes, and snippets.

@rubyisbeautiful
Forked from vsviridov/01_add_cors.config.yaml
Last active April 4, 2017 21:37
Show Gist options
  • Save rubyisbeautiful/796eb149771bb987ca9b38e2c89a528b to your computer and use it in GitHub Desktop.
Save rubyisbeautiful/796eb149771bb987ca9b38e2c89a528b to your computer and use it in GitHub Desktop.
Add CORS to Nginx on AWS Elastic Beanstalk
# This doesn't quite work, and neither do any of the others I found.
# At EB deploy time, it generates the config found in /tmp/passenger-standalone* from a template
#
container_commands:
01_fix_static_cors:
command: "/tmp/fix_static_cors.sh"
files:
"/tmp/fix_static_cors.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash -ex
support_dir=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir)
echo "Adding CORS Config"
proxy_template_a="$support_dir/conf/nginx_config.erb"
proxy_template_b="$support_dir/conf/nginx_config_healthd.erb"
grep Access-Control-Allow $proxy_template_a || sed -i '/location @static_asset {/a \ \ \ \ \ \ \ \ \ \ \ \ add_header 'Access-Control-Allow-Origin' '*';' $proxy_template_a
grep Access-Control-Allow $proxy_template_b || sed -i '/location @static_asset {/a \ \ \ \ \ \ \ \ \ \ \ \ add_header 'Access-Control-Allow-Origin' '*';' $proxy_template_b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment