Bala's Blog

Enable CORS on Apache

September 7 2017
70 words, ~1 min. read
apache 

Follow the steps below to enable CORS on Apache,

  1. Add a new configuration file, say cors.conf, in apache configuration directory, /etc/httpd/conf.d with the following contents,
<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
    Header set Access-Control-Allow-Methods "OPTIONS,POST,PUT,GET,DELETE"
    Header set Access-Control-Allow-Headers "Content-Type, Version"
</IfModule>

Note: Ensure to provide appropriate hostname and headers for Access-Control-Allow-Origin and Access-Control-Allow-Headers values in the above configuration.

  1. Restart or reload apache, to ensure changes are applied
apachectl -k graceful