Page 1 of 2

How do I add Access-Control-Allow-Origin in vestacp? cors

Posted: Mon Dec 28, 2015 10:08 am
by lokali
i'm using cdn cloudfront and i have error on browser that my font blocked (Access-Control-Allow-Origin)
please anyone can help me how to fix Access-Control-Allow-Origin in vestacp

i have been trying all methods on google i found but all failed.. what conf should i modify? nginx or apache?

Re: How do I add Access-Control-Allow-Origin in vestacp? cors

Posted: Mon Dec 28, 2015 10:48 am
by skurudo
nginx or apache?
Nginx - /home/user/conf/web/nginx.conf (snginx.conf if you have some)

Code: Select all

location ~ \.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$ {
           add_header Access-Control-Allow-Origin "*";
And some usefull URL -> http://enable-cors.org/server_nginx.html

Re: How do I add Access-Control-Allow-Origin in vestacp? cors

Posted: Mon Dec 28, 2015 12:06 pm
by lokali
all of them don't work..

i have tried the first one several times before and don't work..

the second gives me 404 error..

Re: How do I add Access-Control-Allow-Origin in vestacp? cors

Posted: Sat Dec 03, 2016 10:37 am
by lukeseven
Hi,

I am having exactly the same issue running my VPS with nginx web server/CDN cloudfront. It's diving me crazy because I have already tried most of the suggestions and recommendations I found online but no luck.

Still getting these errors in browsers

Access to Font at 'https://css-files.mydomain.com/wp-conte ... f2?v=4.4.0' from origin 'https://css-files.mydomain.com' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains the invalid value 'mydomain.com'. Origin 'https://mydomain.com' is therefore not allowed access.

Access to Font at 'https://css-files.mydomain.com/wp-conte ... ff?v=4.4.0' from origin 'https://css-files.mydomain.com' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains the invalid value 'mydomain.com'. Origin 'https://mydomain.com' is therefore not allowed access.

And some more

I am currently using

Code: Select all

location ~ \.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$ {
           add_header Access-Control-Allow-Origin "*"; 
                }
in my home/mydomain/conf/web/snginx.conf

Please help. Any suggestion or hint will be much appreciated.

Thank

Re: How do I add Access-Control-Allow-Origin in vestacp? cors

Posted: Sat Apr 01, 2017 6:52 am
by web-seo-consulting
same problem here

Re: How do I add Access-Control-Allow-Origin in vestacp? cors

Posted: Tue Jun 27, 2017 8:55 pm
by shanjie
add

add_header Access-Control-Allow-Origin *;

into /etc/nginx/nginx.conf

restart nginx
invalidate those fonts path

Re: How do I add Access-Control-Allow-Origin in vestacp? cors

Posted: Fri Jul 21, 2017 12:23 pm
by pramathesh
Facing the same issue! Anyone found a solution to this?

Re: How do I add Access-Control-Allow-Origin in vestacp? cors

Posted: Tue Jul 25, 2017 9:05 am
by skurudo
(!)
viewtopic.php?f=10&t=10166#p36700

If this don't fit, then please explain, how you test this CORS issue?

Re: How do I add Access-Control-Allow-Origin in vestacp? cors

Posted: Sun Sep 17, 2017 5:15 pm
by raiden
# sudo nano /home/user/conf/web/snginx.conf
Add: add_header Access-Control-Allow-Origin "*";
# sudo service nginx restart
worked for me, also it lack woff2 so you need to add it

Code: Select all

server {
    listen      ip:443;
    server_name cdn.domain.com www.cdn.domain.com;
    location / {
        proxy_pass      https://ip:8443;
        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|odt|pdf|psd|ai|eot|eps|ps|zip|tar|tgz|gz|rar|bz2|7z|aac|m4a|mp3|mp4|ogg|wav|wma|3gp|avi|flv|m4v|mkv|mov|mpeg|mpg|wmv|exe|iso|dmg|swf|woff2)$ {
            add_header Access-Control-Allow-Origin "*";
        }
    }
}

Re: How do I add Access-Control-Allow-Origin in vestacp? cors

Posted: Mon Sep 18, 2017 11:32 am
by youradds
You shouldn't be editing the nginx.conf file directly!!!! Always edit the templates:
/usr/local/vesta/data/templates/web
Failing to do that, will just cause your changes to get lost the next time you update the account from the CP (and can even cause fatal errors, as the template parser does not recognise the new line you added in)

Cheers

Andy