Nik*_*Nik 3 google-chrome nginx angularjs sails.js restangular
我正在使用Chrome浏览器浏览两个域:
一切都由nginx提供。
我收到以下错误:
XMLHttpRequest无法加载http://db.localhost:909 / matches。“ Access-Control-Allow-Origin”标头包含多个值“ *”,但只允许一个。因此,不允许访问源' http://vb.localhost:909 '。
这是两个服务器块的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;
}
Run Code Online (Sandbox Code Playgroud)
}
在sails.js应用程序的config / cors.js文件中,我允许所有域CORS访问:
origin: '*',
Run Code Online (Sandbox Code Playgroud)
似乎在nginx的db.localhost服务器块中添加通配符'*'之前先添加了一个空白域,因为Chrome中的错误是:',*' <-请注意先是空字符,然后是逗号,然后是*(通配符)
我的配置哪里出错了?
Sails.js在sails.js服务器端处理此问题。无需在nginx上添加“ Access-Control-Allow-Origin *”标头。
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;
}
Run Code Online (Sandbox Code Playgroud)
只需在config / cors.js文件中添加正确的属性即可允许所有域的CORS访问:
allRoutes: true, // <-this line necessary!
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8908 次 |
| 最近记录: |