Skip to content

Instantly share code, notes, and snippets.

@tihoho
Created March 2, 2019 19:23
Show Gist options
  • Save tihoho/279e167a268bd8b4e5ba2d626cc18283 to your computer and use it in GitHub Desktop.
Save tihoho/279e167a268bd8b4e5ba2d626cc18283 to your computer and use it in GitHub Desktop.
simple CORS
server {
set $cors_origin "";
set $cors_cred "";
set $cors_header "";
set $cors_method "";
if ($http_origin ~* "^http.*\.yourhost\.com$") {
set $cors_origin $http_origin;
set $cors_cred true;
set $cors_header $http_access_control_request_headers;
set $cors_method $http_access_control_request_method;
}
add_header Access-Control-Allow-Origin $cors_origin;
add_header Access-Control-Allow-Credentials $cors_cred;
add_header Access-Control-Allow-Headers $cors_header;
add_header Access-Control-Allow-Methods $cors_method;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment