Report this

What is the reason for this report?

I cannot get CORS working

Posted on February 25, 2015

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?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

See this post …

CORS Nginx and Apache

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.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.