我们有一个HAProxy设置,对我们的一些后端进行基本authentication。 我们现在要启用CORS请求到我们的后端,但是这对启用了基本auth的用户来说是失败的。 当CORS预先考虑OPTIONS请求时,它不包含auth头,因此失败,请求失败。
有没有办法允许OPTIONS请求没有authrisation但强制所有其他请求?
我们的haproxy.cfg包含以下相关的部分:
#User lists used to enforce HTTP Basic Authentication ... userlist ul_hyknpj6tb-uakf5isp user fred password $6$H/M21cSsvXn$jlEZQV7QL/clhV7JtZkAQf34QAPfZq5sE.zLE.M3gi4K1DV5J6ppc.e1JAOP0CtVxM0.n157llg5tsTp0gPFj1 .... backend b_term_hyknpj6tb-uakf5isp mode http balance roundrobin option forwardfor stick-table type ip size 1k expire 30s store bytes_in_rate(1s),bytes_out_rate(1s) tcp-request content track-sc2 src tcp-request inspect-delay 200ms tcp-request content accept if ! too_many_req tcp-request content accept if WAIT_END rspadd Strict-Transport-Security:\ max-age=16000000;\ includeSubDomains acl is_auth http_auth(ul_hyknpj6tb-uakf5isp) http-request auth realm iiboc if !is_auth server node_hyknpj6tb-uakf5isp_1000 192.31.11.70:7843 check ssl verify required crt fred/fred-internal.pem ca-file bob/bob-internal.cert.pem .....
您可以通过在不需要授权的不同后端处理这些请求来允许OPTIONS请求未经授权:
frontend fe_main acl options_method method OPTIONS use_backend be_options if options_method
其中be_options是类似于b_term_hyknpj6tb-uakf5isp的后端,但没有http请求authentication领域iiboc if!is_auth