Cors Haproxy公司编号';访问控制允许原点';请求的资源上存在标头

Cors Haproxy公司编号';访问控制允许原点';请求的资源上存在标头,cors,haproxy,Cors,Haproxy,我想通过在调用时返回以下内容来配置haproxy以处理CORS: <Header name="Access-Control-Allow-Origin">*</Header> <Header name="Access-Control-Allow-Headers">Origin, X-Requested-With, Content-Type, Accept, Authorization, JSNLog-RequestId, activityId, applicat

我想通过在调用时返回以下内容来配置haproxy以处理CORS:

<Header name="Access-Control-Allow-Origin">*</Header>
<Header name="Access-Control-Allow-Headers">Origin, X-Requested-With, Content-Type, Accept, Authorization, JSNLog-RequestId, activityId, applicationId, applicationUserId, channelId, senderId, sessionId</Header>
<Header name="Access-Control-Max-Age">3628800</Header>
<Header name="Access-Control-Allow-Methods">GET, DELETE, OPTIONS, POST, PUT</Header>

CORS策略已阻止从源站“”访问“”处的XMLHttpRequest:对飞行前请求的响应未通过访问控制检查:请求的资源上不存在“访问控制允许源站”标头。

如果要允许一切,您可以删除配置中的CORS块,并为每个响应设置所需的标题:

frontend https_frontend
    ...
    # BEGIN CORS
    http-response set-header Access-Control-Allow-Origin "*"
    http-response set-header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept, Authorization, JSNLog-RequestId, activityId, applicationId, applicationUserId, channelId, senderId, sessionId"
    http-response set-header Access-Control-Max-Age 3628800
    http-response set-header Access-Control-Allow-Methods "GET, DELETE, OPTIONS, POST, PUT"
    # END CORS


但是,您应该确保使用通配符对您的服务是合适的。如果不是,那么找到一种使用Lua支持编译的HAProxy的方法可能是有意义的。

Thx我会试试
frontend https_frontend
    ...
    # BEGIN CORS
    http-response set-header Access-Control-Allow-Origin "*"
    http-response set-header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept, Authorization, JSNLog-RequestId, activityId, applicationId, applicationUserId, channelId, senderId, sessionId"
    http-response set-header Access-Control-Max-Age 3628800
    http-response set-header Access-Control-Allow-Methods "GET, DELETE, OPTIONS, POST, PUT"
    # END CORS