CORS Header Generator
Generate CORS configuration for common web servers and frameworks
Wildcard origin (*) cannot be used together with Access-Control-Allow-Credentials: true.
Access-Control-Allow-Methods
Comma-separated response headers exposed to client JavaScript.
Preflight cache duration in seconds (default 86400).
HTTP Response Headers
Nginx Location Snippet
location /api/ {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' 'https://example.com';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization';
add_header 'Access-Control-Max-Age' 86400;
add_header 'Content-Type' 'text/plain; charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
add_header 'Access-Control-Allow-Origin' 'https://example.com' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
}