11

I am trying to configure Access-Control-Allow-Origin in Apache to allow certain domains. Below is my httpd configuration

<IfModule mod_headers.c>
   Header set Access-Control-Allow-Origin "*"
</IfModule>

But the above config is not doing anything. Heard that we need to enable mod_headers to make it work. I run this httpd -M command and observed that header module is not present in my Apache. Can you anyone pls tell me how to enable?

ezhil
  • 977
  • 6
  • 15
  • 36

1 Answers1

19

Here is my solution:

  1. Open the file httpd.conf at "your apache folder"/conf
  2. Find the following line using CTRL+f in your text editor: #LoadModule headers_module modules/mod_headers.so
  3. Remove the #
  4. Save and restart your apache.
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Michel Neves
  • 252
  • 2
  • 6
  • This worked for me in 2019! I'm using `Avada` theme on localhost. Is the mod_headers thing only an issue with WAMP? – Eric Hepperle - CodeSlayer2010 Mar 29 '19 at 14:52
  • Don't think so, @EricHepperle-CodeSlayer2010 - there are ways to install Apache on Windows other than WAMP, mod_headers and other modules are a fairly common thing and if or if not they are activated by default / the installations' owners, is up to whoever setups / administrates the installation. – HumanInDisguise Mar 30 '19 at 08:44
  • Very useful note – GGSoft Dec 26 '19 at 20:48
  • On CentOS 8 there is nothing for #LoadModule headers_module modules/mod_headers.so and a search of modules shows "headers_mod" with no further reference. – WilliamK Aug 20 '21 at 08:26