Nginx Access Control Allow Origin
当静态资源文件和主站域名不一样时,字体文件之类的会爆如下错误:
Font from origin 'http://www.typenter.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://www.kernelstudio.com' is therefore not allowed access.
Nginx 解决办法:
1 2 3 | add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,OPTIONS; |
将这段代码添加到
1 | http{} |
或者
1 | server{} |
中, 域名也可以进行通配
1 | *.kernelstudio.com |