• Frederick, your plugin is awesome, but there is a problem with the way the nginx.conf file is generated for Access-Control-Allow-Origin header. When writing the nginx.conf file, you first have the following section:

    location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|woff|xla|xls|xlsx|xlt|xlw|zip)$ {
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, public";
        add_header Link "<$scheme://$host$uri>; rel=\"canonical\"";
        add_header X-Powered-By "W3 Total Cache/0.9.4.1";
    }

    After that, you set the origin header with the following:

    location ~ \.(ttf|ttc|otf|eot|woff|font.css)$ {
       add_header Access-Control-Allow-Origin "*";
    }

    The problem with the above approach, is that the second “location” entry is actually never read, because the first regexp will always match and never get to the second one.

    The fix is fairly simple – instead of creating the second location, just add the below line in the first location:

    if ($request_uri ~* ^.*?\.(eot)|(ttf)|(ttc)|(otf)|(woff)|(woff2)$) {
            add_header Access-Control-Allow-Origin *;
        }

    You can put that at the end, so that the full conf looks like this:

    location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|woff|xla|xls|xlsx|xlt|xlw|zip)$ {
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, public";
        add_header Link "<$scheme://$host$uri>; rel=\"canonical\"";
        add_header X-Powered-By "W3 Total Cache/0.9.4.1";
        if ($request_uri ~* ^.*?\.(eot)|(ttf)|(ttc)|(otf)|(woff)|(woff2)$) {
            add_header Access-Control-Allow-Origin *;
        }
    }

    After this is done, the server will always add the correct Origin header to fonts and they will load without an error.

    To anyone who has been getting font loading errors when hosting minified CSS files, the above should be an easy fix. Don’t forget to purge the CDN after you do this!

    Frederick, please include the above fix in the next update of W3 Total Cache.

    Thank you!

    https://wordpress.org/plugins/w3-total-cache/

  • The topic ‘NGIX – Easy Origin Fix’ is closed to new replies.