【发布时间】:2015-12-21 08:36:00
【问题描述】:
通过我的 NGinx 设置,我能够拦截来自 ajax 预检的 OPTIONS 请求,并使用正确的 CORS 标头和 200 响应进行响应,以便请求可以继续向前。我正在尝试将我的前端代理整合到 HAProxy 中,并且在让这块拼图正常工作时遇到了一些问题。
我的特殊问题是,虽然我能够在服务器能够正确响应 OPTIONS 请求时添加正确的 CORS 选项,但在预检请求时,一些后端无法处理/响应 405 错误发布。我的 haproxy.cfg 包含以下用于添加标题的行:
capture request header origin len 128
http-response add-header Access-Control-Allow-Origin %[capture.req.hdr(0)] if { capture.req.hdr(0) -m found }
rspadd Access-Control-Allow-Credentials:\ true if { capture.req.hdr(0) -m found }
rspadd Access-Control-Allow-Headers:\ Origin,\ X-Requested-With,\ Content-Type,\ Origin,\ User-Agent,\ If-Modified-Since,\ Cache-Control,\ Accept if { capture.req.hdr(0) -m found }
rspadd Access-Control-Allow-Methods:\ GET,\ POST,\ PUT,\ DELETE,\ OPTIONS if { capture.req.hdr(0) -m found }
rspadd Access-Control-Max-Age:\ 1728000 if { capture.req.hdr(0) -m found }
中给出的解决方案:
How to send a response with HAProxy without passing the request to web servers 在您设置客户端请求的所有正确标头时有效,但不是动态的,这不是理想的解决方案。
任何帮助将不胜感激!
【问题讨论】:
-
我得到 [2016-04-19 12:49:54.625] uaa - 5213 [http-bio-8080-exec-5] .... DEBUG --- CorsFilter: CORS 处理完成对于:URI:/login.do;方案:https;主机:uaa.testinception25.io;端口:443;来源:skyfallui-testinception25.com;方法:POST 状态:403 帮我设置一下这个的haproxy
标签: ajax cors haproxy preflight