## 问题现象

某天发现项目中的请求接口报错如下:

> The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed.

应该是重复设置了跨域的响应头。

## 解决方案

```nginx
proxy_hide_header Access-Control-Allow-Origin;
proxy_hide_header Access-Control-Allow-Credentials;
add_header Access-Control-Allow-Origin $http_origin;
add_header Access-Control-Allow-Credentials true;
```

先用 `proxy_hide_header` 隐藏上游返回的跨域头,再统一设置,就不会出现多个值的问题。

Last modification:June 19, 2026
如果觉得我的文章对你有用,请随意赞赏