Skip to content

Instantly share code, notes, and snippets.

@wstam88
Forked from adrianorsouza/NGINX-CORS+CSP.conf
Created August 24, 2016 09:50
Show Gist options
  • Save wstam88/c86bc9e4e9e70d56fcc2abd1d228f6ce to your computer and use it in GitHub Desktop.
Save wstam88/c86bc9e4e9e70d56fcc2abd1d228f6ce to your computer and use it in GitHub Desktop.
Nginx CORS and CSP configuration for wildcard origin domains
server {
...
add_header Content-Security-Policy "default-src 'none'";
add_header X-Content-Security-Policy "default-src 'none'";
add_header X-WebKit-CSP "default-src 'none'";
add_header "Access-Control-Allow-Headers" "X-Requested-With";
if ( $http_origin ~* (https?://(.+\.)?(domain1|domain2|domain3)\.(?:me|co|com)$) ) {
set $cors "$http_origin";
}
add_header "Access-Control-Allow-Origin" "$cors";
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment