Skip to content

Instantly share code, notes, and snippets.

@andybeak
Last active August 22, 2019 20:53
Show Gist options
  • Save andybeak/50cf22ef17521e2e7a6d9d20630b60d3 to your computer and use it in GitHub Desktop.
Save andybeak/50cf22ef17521e2e7a6d9d20630b60d3 to your computer and use it in GitHub Desktop.
nginx cors allow origins #course #book
// See https://nginx.org/en/docs/http/ngx_http_map_module.html
// This sets the value of $cors_header depending on the value of $http_origin
map $http_origin $cors_header{
default "";
"~^(https:\/\/safedomain\.com)$" "$http_origin";
"~^(https:\/\/anotherdomain\.com)$" "$http_origin";
}
server {
listen 80;
listen [::]:80;
// we include the value of $cors_header which we set to the value
// of the http origin we want to allow
add_header 'Access-Control-Allow-Origin' "$cors_header";
// ... remaining CORS headers and server body continue ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment