Nginx – Enable Cross Origin Scripting on Nginx from retina.js to load files from another URL

.htaccessamazon s3nginxWordpress

Im running a retina image plugin along with W3 Cache for CDN support. W3 cache moves images to S3, but the JS file won't server the files from there due to the difference in URL (it goes from h ttp://mysite.com to h ttp://assets.mysite.com)

I found a post which says to enable this just add this to your .htaccess

# ----------------------------------------------------------------------
# CORS-enabled images (@crossorigin)
# ----------------------------------------------------------------------
# Send CORS headers if browsers request them; enabled by default for images.
# developer.mozilla.org/en/CORS_Enabled_Image
# blog.chromium.org/2011/07/using-cross-domain-images-in-webgl-and.html
# hacks.mozilla.org/2011/11/using-cors-to-load-webgl-textures-from-cross-domain-images/
# wiki.mozilla.org/Security/Reviews/crossoriginAttribute
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
# mod_headers, y u no match by Content-Type?!
<FilesMatch "\.(gif|png|jpe?g|svg|svgz|ico|webp)$">
SetEnvIf Origin ":" IS_CORS
Header set Access-Control-Allow-Origin "*" env=IS_CORS
</FilesMatch>
</IfModule>
</IfModule>

and then the JS will be able to load the images from S3 – but I have no idea how to do this on Nginx. Could someone give me an easy example?

Original post this was form is – http://wordpress.org/support/topic/doesnt-work-with-cdn-w3-total-cache?replies=4

Best Answer

Check out this gist. You will want to tweak it a bit for your domain and cache preferences.

Related Topic