markdown 在HAProxy中设置CORS
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 在HAProxy中设置CORS相关的知识,希望对你有一定的参考价值。
```
frontend localnodes
bind *:80
reqadd X-Forwarded-Proto:\ http
# Add CORS headers when Origin header is present
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-Methods:\ GET,\ HEAD,\ OPTIONS,\ POST,\ PUT 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,\ Accept,\ X-Requested-With,\ Content-Type,\ Access-Control-Request-Method,\ Access-Control-Request-Headers,\ Authorization if { capture.req.hdr(0) -m found }
default_backend backend_apps
frontend localnodes-https
# Certificate
bind *:443 ssl crt /etc/ssl/private/domain_com.pem
reqadd X-Forwarded-Proto:\ https
# Add CORS headers when Origin header is present
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-Methods:\ GET,\ HEAD,\ OPTIONS,\ POST,\ PUT 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,\ Accept,\ X-Requested-With,\ Content-Type,\ Access-Control-Request-Method,\ Access-Control-Request-Headers,\ Authorization if { capture.req.hdr(0) -m found }
default_backend backend_apps
backend backend_apps
# Force HTTPS
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
redirect scheme https if !{ ssl_fc }
server App1 192.168.1.201:80 check
server App2 192.168.1.202:80 check
server App3 192.168.1.203:80 check
server App4 192.168.1.204:80 check
server App5 192.168.1.205:80 check
```
以上是关于markdown 在HAProxy中设置CORS的主要内容,如果未能解决你的问题,请参考以下文章
在 Tomcat 中设置 CORS 标头
如何在门户的 Azure BLOB 存储中设置 CORS?
尽管在 Flask 中设置了响应标头,但 CORS 错误
我在我的 Rails 应用程序中设置了 CORS,但我仍然收到错误 [重复]
Cors问题我还由于cors在pkg.json中设置了代理并根据它设置了api,但是这个错误没有被删除
带有域字段的 CORS cookie 仅在使用 jQuery AJAX 的 Firefox 中设置