Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Enable CORS for Apache httpd server? (Step-By-Step Process)

I was wondering if anybody can help me set up CORS on my Apache web server. I would appreciate a step-by-step process because many sites online are telling me different things. Like what do I need to do on my httpd.conf or ssl.conf files, where to put my .htaccess file, etc.

like image 785
user3851283 Avatar asked Aug 28 '15 14:08

user3851283


2 Answers

The above answer is correct and put Inside the httpd.conf. This should be changed to whatever you set Document Root.

On Ubuntu, httpd.conf is located in the directory /etc/apache2. apache2.conf is also located in /etc/apache2.

On CENTOS 6 httpd.conf in the path /etc/httpd/conf/httpd.

<Directory "/var/www/html">
        Header set Access-Control-Allow-Origin "*"
</Directory>
like image 50
Panneerchelvam Piratheepan Avatar answered Oct 24 '22 00:10

Panneerchelvam Piratheepan


# edit your conf/httpd.conf file.  Verify that the headers module is loaded
LoadModule headers_module modules/mod_headers.so

# to whitelist every origin, use
Header set Access-Control-Allow-Origin "*"

More info: http://enable-cors.org/server_apache.html

like image 43
Kevin Seifert Avatar answered Oct 24 '22 01:10

Kevin Seifert