今天發現訪問了html5頁面,報瞭如下錯誤:
Font from origin 'http://design.ehaoyao.com' 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://w.ehaoyao.com' is therefore not allowed access.
聽設計說是,字體跨域問題,孤陋寡聞第一次碰到,查了一下還真的有這麼一回事。
Access-Control-Allow-Origin是HTML5中定義的一種服務器端返回Response header,用來解決資源(比如字體)的跨域權限問題。它定義了該資源允許被哪個域引用,或者被所有域引用(google字體使用*表示字體資源允許被所有域引用)。
解決方法:
<!--在nginx.conf中配置--> http { ...... add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,OPTIONS; ...... }
但是有人又說這種安全性不高,不是太懂,參考一下:
http://www.51testing.com/html/96/215196-829360.html
http://ju.outofmemory.cn/entry/63586