Cors / Access-Control-Allow-Origin not working

Hi,

I am trying to enable Cors or add Access-Control-Allow-Origin header, but doesn’t seem to be working:

bow.mydomain.com, bow.anotherdomain.com {
        log /var/log/caddy/bow.log
        errors /var/log/caddy/errors.log
        root /var/www/bow/
        fastcgi / /run/php/php7.2-fpm.sock php {
          ext .php
          split .php
          index index.php
        }
        status 404 {
        /txtdb.class.php
        }
        header / Access-Control-Allow-Origin: *
}

and

bow.mydomain.com, bow.mydomain.com {
        log /var/log/caddy/bow.log
        errors /var/log/caddy/errors.log
        root /var/www/bow/
        fastcgi / /run/php/php7.2-fpm.sock php {
          ext .php
          split .php
          index index.php
        }
        status 404 {
        /txtdb.class.php
        }
        cors
}

Hi @madrian,

Did you reload the configuration after adding the header directive to your Caddyfile?

I note also that you’ve set a header named Access-Control-Allow-Origin: when the header name should actually be Access-Control-Allow-Origin. The extra : might be a sticking point, or maybe not, I’m not sure - but I do know you don’t need to have it there.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.