Skip to main content
KalkuNet

CORS Header Generator — Access-Control-Allow-Origin for Nginx, Express and Caddy

Generate Nginx, Express & Caddy CORS headers for allowed origins & methods.

Runs in your browserWeb · HTTP, URLs & Redirects
Methods

Paste the map block at http { } level and the add_header/if lines inside the API location. add_header is repeated inside if because Nginx does not inherit it into that block.

When to use the CORS (Access-Control-Allow-*) Header Generator

  • Several origins, safely

    Access-Control-Allow-Origin can hold only one origin. For several origins this config matches the request's Origin against your list and echoes it, with Vary: Origin so caches do not mix them up.

  • Preflight answered in full

    OPTIONS requests get a 204 with the allowed methods, headers and Max-Age, so PUT, DELETE or an Authorization header no longer fail in the browser.

  • Browser rules checked

    Combinations browsers reject are flagged: * together with credentials, origins with a path or trailing slash, and a Max-Age above Chrome's 7,200-second cap.

  • Tested with cross-origin fetch

    Every config runs on a real server, then Chrome calls the API from allowed and forbidden origins, preflight with cookies included.

Frequently asked questions

Why do I still get CORS errors with the headers set?

Often because the headers are only sent on successful responses. In Nginx, add_header without always is not sent on 4xx/5xx errors, so this tool always adds always.

Do GET and POST need to be listed?

GET, HEAD and POST are allowed without being listed, as long as they use standard headers. The method list matters for PUT, PATCH, DELETE and others.

Can I allow every subdomain?

Yes, write https://*.example.com. The config uses a regular expression that matches any subdomain but still refuses look-alikes such as example.com.evil.test.

What is a preflight request?

Before sending PUT, PATCH or a request with an Authorization header to another site, the browser first sends an OPTIONS request asking whether that method and those headers are allowed. The answer is cached for Max-Age so it is not repeated on every request.

Learn more