---
title: "nginx 配置 CORS 支持跨域访问"
author: "bo_hai"
date: "2014-11-11T20:26:54Z"
tags: []
categories: ["Web前端"]
slug: "nginx-cors"
draft: false
lastmod: "2014-11-11T20:26:54Z"
id: 2154706
url: "https://bo-hai.iteye.com/blog/2154706"
---

CSS代码设置了一些字体，如果跨域访问这些字体，就会加载失败。错误信息如下：

```
已阻止交叉源请求：同源策略不允许读取 http://XXXXXX.com/aimall/spm_modules/fontawesome/fonts/fontawesome-webfont.woff?v=4.2.0 上的远程资源。可以将资源移动到相同的域名上或者启用 CORS 来解决这个问题。
```

   
![](http://dl2.iteye.com/upload/attachment/0103/0634/f8fedc77-653c-3b9b-91b2-96a343701a3c.png)  
 

解决方案是：在nginx的配置中进行配置，配置如下：

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