Question

I cannot get CORS working

Posted February 25, 2015 9k views

Let me preface this with the fact it’s my first time setting up anything in a cloud server, and my previous knowledge consists of doing a local WAMP stack and using web hosting solutions.

I’ve set up an Ubuntu LAMP Install fine, and what I can’t get to work is the CORS! I suspect the module headers, because I don’t seem to get any change on my response headers. I’ve enabled the mod:

sudo a2enmod headers
sudo service apache2 restart

I tried the same .htaccess I used before doing the migration, but it didn’t work, thus for testing purposes I’m using only:

Header set Access-Control-Allow-Origin "*"

Then I did a apachectl -t, which gives me Syntax OK. The following is an excerpt of an apachectl -M:

headers_module (shared)

It should be working, but it’s not. What am I doing wrong?

1 comment
  • Additional information: I figured it’s a subdomain related issue. If the file gets served from domain.com/assets/ I get the right response header, if it gets served from assets.domain.com/ it doesn’t.

    I’m currently attempting to determine if it has anything to do with my virtual hosts.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
3 answers

Answering it myself. Typical “argh I dumbly overlooked this small detail”, it was actually a misconfiguration in the <Directory> for this subdomain in particular.

So, if you get oddities where CORS works for the real path but not a virtual host (subdomain in this case), and this subdomain works fine except for this detail make sure to check if you’ve set everything for Apache right at /etc/apache2/sites-available/example.com.conf, exactly as you did before at 000-default.conf.

Submit an Answer