Results 1 to 8 of 8

Thread: How to enable CORS on Apache + Nginx ?

  1. #1
    Join Date
    Mar 2013
    Posts
    136

    How to enable CORS on Apache + Nginx ?

    I have this error:

    Code:
    Access to Font at 'https://originaldomain/fonts/*.woff' from origin 'https://www.testdomain.net' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.testdomain.net' is therefore not allowed access.
    Please help me

  2. #2
    Join Date
    Apr 2009
    Posts
    2,186
    Add the following to .htaccess on the domain that is hosting the fonts (this will allow any domains to load the fonts):

    Code:
    <FilesMatch "\.(js|jpg|css|eot|otf|svg|ttf||woff|woff2)$">
    <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
    </IfModule>
    </FilesMatch>
    (Remove the extensions you do not want to allow from the code above.) Edit: This is for Apache, I have no idea about Nginx as I don't use it.
    Last edited by ditto; 08-11-2018 at 10:01 AM.

  3. #3
    Join Date
    Mar 2013
    Posts
    136
    Quote Originally Posted by ditto View Post
    Add the following to .htaccess on the domain that is hosting the fonts (this will allow any domains to load the fonts):

    Code:
    <FilesMatch "\.(js|jpg|css|eot|otf|svg|ttf||woff|woff2)$">
    <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
    </IfModule>
    </FilesMatch>
    (Remove the extensions you do not want to allow from the code above.) Edit: This is for Apache, I have no idea about Nginx as I don't use it.
    It is not working , I think because of nginx!

  4. #4
    Join Date
    Apr 2009
    Posts
    2,186
    Try to empty all cache in your browser, then restart your browser and check again. If not, you would need to modify the .htaccess code to work on Nginx.

  5. #5
    Join Date
    Mar 2013
    Posts
    136
    Quote Originally Posted by ditto View Post
    Try to empty all cache in your browser, then restart your browser and check again. If not, you would need to modify the .htaccess code to work on Nginx.
    I searched a lot, but there is no success yet, So I opened this topic to find the answer.

    I tried many htaccess or httpd.conf codes + empty cache + restart nginx and apache but no success...

  6. #6
    Join Date
    Apr 2009
    Posts
    2,186
    All I can say is that my code work on Apache, only time it will not work is if the site is password protected. So unless your site is password protected, then it must be Nginx that is the problem.

  7. #7
    Join Date
    Mar 2013
    Posts
    136
    Quote Originally Posted by ditto View Post
    All I can say is that my code work on Apache, only time it will not work is if the site is password protected. So unless your site is password protected, then it must be Nginx that is the problem.
    I know Nginx serving static files , I tried some codes on nginx conf or vhost file too but no success!

  8. #8
    Join Date
    Mar 2013
    Posts
    136
    anyone can help?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •