Vvv: Font from origin domain.dev has been blocked... (CORS and browsersync)

Created on 2 Jul 2015  路  12Comments  路  Source: Varying-Vagrant-Vagrants/VVV

Browersync (run via gulp) is using localhost:3000 which works great except for Fonts and SVGs hover trigger cross site scripting protection.

Font from origin 'http://sitename.dev' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

The browser URL is localhost:3000 for gulp-browsersync, but the XML assets are getting loaded from http://sitename.dev/ I get, that just have no idea how to get it working.

I thought this should work: https://gist.github.com/Stanback/7145487 and tried adding to nginx-wp-common.conf and alternatively sitename.conf. Neither worked however.

Maybe I'm going about this all wrong? Either advise on how to allow localhost:3000 to load from *.dev, or an alternative way of using browsersync would be appreciated here.

Most helpful comment

Worked for me in Crear P谩gina Web | WebArt.es

# Allow access from all domains for webfonts.
<IfModule mod_headers.c>
  <FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css|css)$">
    Header set Access-Control-Allow-Origin "*"
  </FilesMatch>
</IfModule>

I've put this code in .htaccess file and website works 100% fine for me...

Greetings from Barcelona!

All 12 comments

After much trial and error I got this working, I'm not really happy with the way it's working, maybe someone can still clarify or suggest alternatives.

to: /etc/nginx/nginx-wp-common.conf
after the first location block I added:

location ~* \.(eot|ttf|woff|svg)$ {
    add_header Access-Control-Allow-Origin *;
}

This _is_ the file referenced by the individual conf files:
/srv/config/nginx-config/sites/{site_name}.conf

Confusion:
There is a file adjacent to the individual conf files here:
/srv/config/nginx-config/nginx-wp-config.conf which apparently does nothing.

Is deliberate or a bug?

Not entirely deliberate, though not a bug either. :) Need to think through the consequences of adding Access-Control-Allow-Origin by default. It may be fine, especially because of the local setup, but it might be best left as is.

I would think adding allowing "localhost" by default would be sufficient, rather than "*", but I don't know if the port is going to matter (pretty naive when it comes to nginx config)

thanks @jb510 ... your post saved me from the same trial and error!

Glad it helped :D

Thanks @jb510, fixed it for me, too.

Worked for me in Crear P谩gina Web | WebArt.es

# Allow access from all domains for webfonts.
<IfModule mod_headers.c>
  <FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css|css)$">
    Header set Access-Control-Allow-Origin "*"
  </FilesMatch>
</IfModule>

I've put this code in .htaccess file and website works 100% fine for me...

Greetings from Barcelona!

Also woff2 :
ttf|ttc|otf|eot|woff|woff2|font.css|css

Marking as closed due to inactivity, PR welcome if this is still an issue

thanlk all
thats work for me .

# Allow access from all domains for webfonts. <IfModule mod_headers.c> <FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css|css)$"> Header set Access-Control-Allow-Origin "*" </FilesMatch> </IfModule>

@miladbinyaz that's an Apache HTAccess rule, VVV uses Nginx

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rwrobe picture rwrobe  路  4Comments

caseyallen386 picture caseyallen386  路  5Comments

joelworsham picture joelworsham  路  5Comments

rwrobe picture rwrobe  路  4Comments

PorterBytes picture PorterBytes  路  5Comments