CORSヘッダー生成
主要なWebサーバーやフレームワーク向けのCORS設定を生成します。
ワイルドカードオリジン(*)は Access-Control-Allow-Credentials: true と併用できません。
Access-Control-Allow-Methods
クライアントJavaScriptに公開するレスポンスヘッダー(カンマ区切り)。
プリフライトのキャッシュ時間(秒、デフォルト: 86400)。
HTTPレスポンスヘッダー
Nginx location スニペット
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;
}