• 请不要在回答技术问题时复制粘贴 AI 生成的内容
awker
V2EX  ›  程序员

vue 静态页面在浏览器跨域 options 请求时,会返回多个 Access-Control-Allow-Origin header 问题

  •  
  •   awker · Mar 21, 2019 · 5868 views
    This topic created in 2647 days ago, the information mentioned may be changed or developed.

    vue 静态页面部署在 http://dev.xxx.cn ,其中有页面会请求 http://foo.xxx.cn ,这时候在浏览器看到 options 请求报错为

    Access to XMLHttpRequest at 'http://foo.xxx.cn/upload/8b' from origin 'http://dev.xxx.cn' 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 'http://dev.xxx.cn, *', but only one is allowed.
    

    但我 nginx 端只设置了 一个 Access-Control-Allow-Origin

    add_header 'Access-Control-Allow-Origin' '*'
    

    后端服务也没有设置 Access-Control-Allow-Origin,

    有大神遇到过这个问题吗?

    1 replies    2019-03-21 21:19:03 +08:00
    awker
        1
    awker  
    OP
       Mar 21, 2019   ❤️ 1
    找到问题了 http://dev.xxx.cnhttp://foo.xxx.cn 放在同一台 nginx,所以会出现这个问题。
    http://foo.xxx.cn 或者 http://dev.xxx.cn 放在另外一台 nginx 就行了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2598 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 05:02 · PVG 13:02 · LAX 22:02 · JFK 01:02
    ♥ Do have faith in what you're doing.