简体   繁体   English

Nginx中的Angular2-缺少CORS标头'Access-Control-Allow-Origin'

[英]Angular2 in nginx - CORS header 'Access-Control-Allow-Origin' missing

So I have taken the heroes tutorial from Angular 2, used it with an angular-cli project. 因此,我从Angular 2那里学习了英雄教程,并将其与angular-cli项目结合使用。 Running ng serve and using in memory api, it works. 运行ng serve并在内存api中使用它可以正常工作。

Changed the server url to point to my tomcat server that is providing a rest api. 更改了服务器URL,使其指向提供REST API的Tomcat服务器。 I have tested this with curl and it gives back data. 我已经用curl进行了测试,它可以返回数据。

I then built it for production and put the resulting bundles into nginx on the same machine as tomcat. 然后,我将其构建用于生产,并将生成的捆绑包与tomcat放在同一台计算机上的nginx中。

Run in Firefox, get correct page but no data. 在Firefox中运行,获取正确的页面,但没有数据。 Console shows the GET is OK. 控制台显示GET正常。 But I do get 但是我得到了

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://centos7:8080/heroes/heroes. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

Other questions in StackOverFlow on this topic say that both must be in the same domain, which they are, the tomcat server is centos7:8080/heroes/heroes and the nginx server is centos7/ 关于此主题的StackOverFlow中的其他问题表明,两者都必须位于同一个域中,tomcat服务器为centos7:8080 / heroes / heroes,而nginx服务器为centos7 /

Should I have to open up CORS? 我是否必须开放CORS? I have seen http://enable-cors.org/server_nginx.html so I need to add this in nginx.conf? 我看过http://enable-cors.org/server_nginx.html,所以需要在nginx.conf中添加它吗?

Does anyone have any ideas? 有人有什么想法吗?

Regards 问候

So I am not if this is the abolute answer but it removed the CORS error in browser console. 因此,如果这是正确的答案,那么我不是,但是它消除了浏览器控制台中的CORS错误。

In my grails 3 rest api application, I added the grails 3 COR interceptor https://github.com/appcela/grails3-cors-interceptor . 在我的grails 3 rest api应用程序中,我添加了grails 3 COR拦截器https://github.com/appcela/grails3-cors-interceptor

I now get a different problem but I will raise that in a separate question. 我现在遇到另一个问题,但我将在另一个问题中提出。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 angular js nginx cors-没有'Access-Control-Allow-Origin'标头 - angular js nginx cors - No 'Access-Control-Allow-Origin' header Nginx CORS'Access-Control-Allow-Origin'标头 - Nginx CORS 'Access-Control-Allow-Origin' header (Laravel和Nginx)CORS标头'Access-Control-Allow-Origin'与'(null)'不匹配 - (Laravel & Nginx) CORS header ‘Access-Control-Allow-Origin’ does not match ‘(null)’ Nginx:被 CORS 策略阻止:“Access-Control-Allow-Origin”标头包含多个值 - Nginx : blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values NodeJS 或 Nginx 上发生 Access-Control-Allow-Origin cors 错误 - Access-Control-Allow-Origin cors error happening on NodeJS or Nginx 为什么我得到原因:成功返回数据时缺少 CORS 标头“Access-Control-Allow-Origin” - Why I get Reason: CORS header 'Access-Control-Allow-Origin' missing while data is returned successfully 当它出现在控制台中时,“CORS 中缺少 Access-Control-Allow-Origin” - "Access-Control-Allow-Origin missing in CORS" when it appears in the console NGINX的“Access-Control-Allow-Origin”标头包含多个值 - NGINX 'Access-Control-Allow-Origin' header contains multiple values 流星nginx和“ Access-Control-Allow-Origin”标头,此处为圆圈 - meteor nginx and the 'Access-Control-Allow-Origin' header, A circle here NGINX CORS Policy Fails when Access-Control-Allow-Origin Header is not present, but then sets it multiple times when header is present - NGINX CORS Policy Fails when Access-Control-Allow-Origin Header is not present, but then sets it multiple times when header is present
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM