跳转到主要内容
kitlocal.dev

CORS 头生成器

本地运行

100% 在你的浏览器中处理。输入和输出绝不会离开你的设备。

为常见 Web 服务器和框架生成 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;
}