烧瓶CORS在生产中不使用Nginx,但在没有Nginx的地方使用

烧瓶CORS在生产中不使用Nginx,但在没有Nginx的地方使用,nginx,flask,Nginx,Flask,我目前有一个问题,我已经设置了一个烧瓶应用程序 CORS(app) 但我得到了每一种柯尔的错误作为回应。但这只发生在生产中。 我会犯这样的错误 Access to XMLHttpRequest at 'https://example.com' from origin 'https://2e11e606fda6.ngrok.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present

我目前有一个问题,我已经设置了一个烧瓶应用程序

CORS(app)
但我得到了每一种柯尔的错误作为回应。但这只发生在生产中。 我会犯这样的错误

Access to XMLHttpRequest at 'https://example.com' from origin 'https://2e11e606fda6.ngrok.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

我还通过nginx
location/
块尝试了头中CORS请求的不同变体,但这会导致一些类似的错误


任何帮助都将不胜感激。

因此,经过几个小时的精疲力竭之后。我碰巧查了一下nginx的访问日志

那里显示了一个错误代码413


从那时起,我就能够修复我的nginx配置,允许文件上传工作。因此,CORS问题似乎并不总是与CORS有关,而是nginx报告错误的方式。

CORS是一件棘手的事情,特别是在Flask中。如果发生回溯,可能不会调用Flask CORS请求处理程序,也不会添加头。在生产中,通过NGINX添加CORS头可能很有用,请看以下答案:
Access to XMLHttpRequest at 'https://example.com' from origin 'https://2e11e606fda6.ngrok.io' 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 '*, *', but only one is allowed