我需要帮助CORS标头和HAProxy配置。
我在haproxy配置中添加了以下内容:
# Add CORS headers when Origin header is present
capture request header origin len 128
http-response set-header Access-Control-Allow-Origin %[capture.req.hdr(0)] if { capture.req.hdr(0) -m found }
http-response set-header Access-Control-Allow-Methods GET,\ HEAD,\ OPTIONS,\ POST,\ PUT if { capture.req.hdr(0) -m found }
http-response set-header Access-Control-Allow-Credentials true if { capture.req.hdr(0) -m found }
http-response set-header Access-Control-Allow-Headers X-Stream-Output,\ X-Chunked-Output,\ X-Content-Length if { capture.req.hdr(0) -m found }
http-response set-header Access-Control-Expose-Headers X-Stream-Output,\ X-Chunked-Output,\ X-Content-Length if { capture.req.hdr(0) -m found }它似乎将CORS头返回给浏览器,但我仍然在浏览器的JSON调用中得到403禁止。这是我尝试调用的URL:
https://ipfs.blockchaingraph.org:5001/api/v0/cat/QmdKPs1N6gH3R62BGssakAaEdFv14rp6fVVQy36yzdFQdT
当我尝试调用第三方类似查询时,它工作得很好:
https://ipfs.infura.io:5001/api/v0/cat/QmdKPs1N6gH3R62BGssakAaEdFv14rp6fVVQy36yzdFQdT
我比较了两个响应的报头。两者看起来很相似。我想知道我在这里遗漏了什么。
我怀疑后端服务器正在阻止基于某些标头的请求。我试着删除Origin:"http-request del-header Origin",但没有帮助
发布于 2018-10-14 19:14:47
是的,这是后端服务器拒绝请求。当我在haproxy配置中添加referer header删除时,这个问题消失了:
http-request del-header Origin
http-request del-header Refererhttps://stackoverflow.com/questions/52796235
复制相似问题