weixin_33727510 2016-08-02 17:14 采纳率: 0%
浏览 115

Nginx Web浏览器的CORS问题

I'm working on an AngularJS Application which uses an external API and I got a weird issue (CORS). I made a lot of research that does not fix the issue.

When I hit my API the preflight request is good (status 204 No-Content), but when the server responds with a another status code than 2xx (200, 204 etc...) I got the CORS issue.

If my server send back 2xx as status code is alright we have no CORS issue but if another status code is sent here is the problem.

API : Sylex(PHP Framework) running under Nginx

Front application : AngularJS - using webpack

XHR VIEW :

XHR view

Console CORS Error :

Console CORS Error

  • 写回答

1条回答 默认 最新

  • helloxielan 2016-08-09 20:35
    关注

    After a day of search I figured out where the CORS was coming from. The Nginx configuration was ok. It was the API.

    During the preflight request (OPTIONS) the server let passed the request because NGINX allowed the origin and header (access-control-allow-origin, access-control-allow-headers),

    but when the API sends back the response the headers were not set up.

    I fixed it by adding the access-control-allow-origin and access-control-allow-headers to the response.

    IMPORTANT: I figured out data weren't recoverable in the response with the 200 status code on the webbrowser. To fix it remove the headers added in the others responses (5xx, 4xx, etc..) (I don't know if its just in my case)

    I haven't developed the API that's why it takes me a day to figure it out. Hope I will help someone with this use case :)

    评论

报告相同问题?

悬赏问题

  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站