Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to allow Cross domain request in apache2

Tags:

cors

apache

This is my configuration file.

<VirtualHost *:80>     ServerAdmin webmaster@localhost     ServerName localhost:80     DocumentRoot /var/www/XXX     <Directory />         Options None         AllowOverride None         Order deny,allow         Deny from all     </Directory>     <Directory /var/www/qvbn-app-web-ctrl>         Options FollowSymLinks         AllowOverride AuthConfig FileInfo         Order allow,deny         Allow from all         Header set Access-Control-Allow-Origin "*"     </Directory>     ErrorLog ${APACHE_LOG_DIR}/error.log     LogLevel warn     CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 

When i am trying to reload apache2 iT is giving error as :

   Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration     Action 'configtest' failed. 

I don't know how to enable CORS. I followed this: http://enable-cors.org/server_apache.html

like image 847
Prakash Kuma Avatar asked Mar 19 '15 16:03

Prakash Kuma


People also ask

What is Apache CORS?

Cross Origin Resource Sharing (CORS) allows your web server to accept and serve requests from other domains. By default, CORS is disabled in Apache. You need to set Access-Control-Allow-Origin Header to enable CORS in Apache.


1 Answers

OS=GNU/Linux Debian Httpd=Apache/2.4.10 

Change in /etc/apache2/apache2.conf

<Directory /var/www/html>      Order Allow,Deny      Allow from all      AllowOverride all      Header set Access-Control-Allow-Origin "*" </Directory> 

Add/activate module

 a2enmod headers  

Restart service

/etc/init.d/apache2 restart 
like image 93
Amit Vujic Avatar answered Oct 13 '22 22:10

Amit Vujic