Last active
August 22, 2019 20:53
-
-
Save andybeak/50cf22ef17521e2e7a6d9d20630b60d3 to your computer and use it in GitHub Desktop.
nginx cors allow origins #course #book
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
// 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