跳至主要內容
kitlocal.dev

CORS 標頭產生器

本機執行

100% 在你的瀏覽器中處理。輸入與輸出絕不會離開你的裝置。

為常見網頁伺服器與框架產生 CORS 設定。

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;
}