Nginx跨域冲突问题

nginx请求

应用服务和nginx2服务都配置了跨域,会导致一下问题,’Access-Control-Allow-Origin’重复

1
Access to fetch at 'https://gpt-core.wxqcloud.fun/api/v1/chat/completions' from origin 'https://gpt.wxqcloud.fun' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values 'https://gpt.wxqcloud.fun, https://gpt.wxqcloud.fun', but only one is allowed. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

可以修改nginx服务2的配置 增加proxy_hide_header

1
2
3
4
5
6
proxy_hide_header Access-Control-Allow-Origin;
proxy_hide_header Access-Control-Allow-Methods;
proxy_hide_header Access-Control-Allow-Credentials;
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';