gpt4 book ai didi

angularjs - 'Access-Control-Allow-Origin' header 包含多个值 - nginx + sails.js

转载 作者:行者123 更新时间:2023-12-01 11:36:27 25 4
gpt4 key购买 nike

我将使用 Chrome 浏览器跨越两个域:

一切都由 nginx 提供。

我收到以下错误:

XMLHttpRequest 无法加载 http://db.localhost:909/matches . 'Access-Control-Allow-Origin' header 包含多个值', *',但只允许一个值。 Origin ' http://vb.localhost:909 ' 因此不允许访问。

这是两个服务器 block 的 nginx.conf:

 server {
listen 909;
server_name vb.localhost;

location / {
root "\apps\vb-site\UI\dev";
index index.html;
}
}
server {
listen 909;
server_name db.localhost;
add_header Access-Control-Allow-Origin *;

location / {
proxy_pass http://127.0.0.1:1337;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;

}

在 sails.js 应用程序的 config/cors.js 文件中,我已允许所有域进行 CORS 访问:

 origin: '*',

在 nginx 的 db.localhost 服务器 block 中添加通配符“*”之前,似乎添加了一个空白域,因为 Chrome 中的错误是:', *' <- 注意空字符,然后是逗号,然后是 *(通配符)

我的配置哪里出错了?

最佳答案

Sails.js 在 sails.js 服务器端处理这个问题。无需在 nginx 上添加“Access-Control-Allow-Origin *” header 。

server {
listen 909;
server_name db.localhost;
add_header Access-Control-Allow-Origin *; # <-this line not necessary

location / {
proxy_pass http://127.0.0.1:1337;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;

}

这只是在config/cors.js 文件,允许所有域 CORS 访问:

   allRoutes: true, // <-this line necessary!

关于angularjs - 'Access-Control-Allow-Origin' header 包含多个值 - nginx + sails.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26639143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com