Skip to content

Instantly share code, notes, and snippets.

@CCH0124
Forked from adrianorsouza/NGINX-CORS+CSP.conf
Created September 18, 2023 08:09
Show Gist options
  • Save CCH0124/e94e68a5a5c2744b6cf9826519a06b86 to your computer and use it in GitHub Desktop.
Save CCH0124/e94e68a5a5c2744b6cf9826519a06b86 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