【问题标题】:Kubernetes Nginx upload large file 400 No 'Access-Control-Allow-Origin'Kubernetes Nginx 上传大文件 400 No 'Access-Control-Allow-Origin'
【发布时间】:2018-09-25 09:40:13
【问题描述】:

当我保持 nginx 的 proxy_body_size: 8m 的默认值时。我无法上传文件大小> 8M。然后我像这样配置nginx注解:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: "ingress-name"
  annotations:

    nginx.ingress.kubernetes.io/proxy-body-size: 100m

所以,我现在可以上传 > 8M 的文件。但是,我尝试上传大约 50m 的 CSV 文件,出现错误

无法加载https://api.domain.xxx/import:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin 'https://web.domain.xxx/' 不允许访问。响应的 HTTP 状态代码为 400。

谁能帮我上传最大文件是100m?

谢谢

【问题讨论】:

    标签: file nginx kubernetes cors kubernetes-ingress


    【解决方案1】:

    问题是您尝试从与入口中指定的域不同的域上传文件。它可能是同一个域,但不同的端口、协议(http/https)、前缀为 www. 等

    默认情况下,出于安全考虑,浏览器不允许这些请求。要允许它们,您应该启用 CORS:https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

    幸运的是,在 ingress 中启用 CORS 非常容易,只需在您的 api 的 ingress 资源中添加以下注释即可:

    nginx.ingress.kubernetes.io/enable-cors: "true"
    nginx.ingress.kubernetes.io/cors-allow-methods: "PUT, GET, POST, OPTIONS"
    nginx.ingress.kubernetes.io/cors-allow-origin: "https://web.domain.xxx"
    

    关于这些注释的更多信息here

    【讨论】:

    • 我收到错误Failed to load https://api.domain.xxx/import: The 'Access-Control-Allow-Origin' header contains multiple values 'https://web.domain.xxx, https://web.domain.xxx', but only one is allowed. Origin 'https://web.domain.xxx' is therefore not allowed access.
    • 请重新检查我的小文件是否可以更新,并且前端和api是同一个域(https://web.domain.xxxhttps://api.domain.xxx/import
    • 刚刚更新了域名信息,注意这些注解应该添加到de api的入口,
    • 出于开发目的,您可以使用nginx.ingress.kubernetes.io/cors-allow-origin: "*"接受所有来源
    • 我在上面遇到了同样的错误,"*""https://web.domain.xxx" 案例
    猜你喜欢
    • 2017-12-29
    • 2019-03-18
    • 2018-09-19
    • 2021-08-12
    • 2013-06-28
    • 2020-01-05
    • 1970-01-01
    • 2018-02-04
    • 2019-08-02
    相关资源
    最近更新 更多