1 / 7

Enable CORS in Apache Server

CORS allows you to accept cross domain requests on your website. Here's how to enable CORS in Apache web server. #cors #apache #webdevelopment <br><br>Visit https://ubiq.co/tech-blog/enable-cors-apache-web-server/

Download Presentation

Enable CORS in Apache Server

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. How to Enable CORS in Apache Web Server

  2. Enable headers module Ubuntu/Debian In ubuntu/debian linux, open terminal & run the following command to enable headers module. $ sudo a2enmod headers CentOS/Redhat/Fedora In CentOS/Redhat/Fedora linux, open the Apache configuration file httpd.conf and uncomment the following line by removing # in front of them. LoadModule headers_module modules/mod_headers.so

  3. Enable CORS in Apache Add add_header directive to server block of your NGINX configuration file. server{ ... add_header Access-Control-Allow-Origin *; ... }

  4. Enable CORS from all websites Next, add the “Header add Access-Control-Allow-Origin *” directive to either your Apache config file, or .htaccess file, or Virtual Host configuration file, depending on your requirement. If you add it to your main configuration file, CORS will be enabled to all websites on your server. If you add it to .htaccess file or virtual host configuration file, then it will be enabled for only that file’s website. Here are examples of how to add this directive in different files. You can use any one of them. Directory Tag in Main Configuration File <Directory /var/www/html> ... Header set Access-Control-Allow-Origin "*" ... </Directory>

  5. Enable CORS from one domain If you want to enable CORS for one website domain (e.g example.com), specify that domain in place of wildcard character *. Header add Access-Control-Allow-Origin "example.com"; If you want to enable CORS for multiple domains (e.g example1.com, example2.com,example3.com), specify them separately one after another Header add Access-Control-Allow-Origin "example1.com"; Header add Access-Control-Allow-Origin "example2.com"; Header add Access-Control-Allow-Origin "example3.com"; If you want to enable CORS from localhost, add 127.0.0.1 or localhost in place of domain name Header add Access-Control-Allow-Origin "localhost";

  6. Restart Apache Server Restart Apache web server to apply changes -------------- On Debian/Ubuntu -------------- # apache2 -t # systemctl restart apache2.service -------------- On RHEL/CentOS/Fedora -------------- # httpd -t # systemctl restart httpd.service

  7. Thank You Visit for details https://ubiq.co/tech-blog/enable-cors-apache-web-server/

More Related