Haproxy1.5.1 垮域请求处理(cors)
因为Haproxy 1.5.1 的版本不支持新版的lun.core模块,所以在设置前端的cors的时候会比较复杂。但是也是可以做的。
下面以7480这个端口来做演示:
haproxy.cfg:
listen ceph_rgw bind 0.0.0.0:7480 balance roundrobin errorfile 503 /etc/haproxy/file.http # (3) 所有的503错误都用这个自己写的http response文件重写 use_backend cors_headers if METH_OPTIONS # (1) 所有的OPTIONS请求调度到cors_headers这个backend default_backend rgw_back # (4) 正常的其他请求走这里 backend rgw_back # (5) 正常的逻辑 rspadd Access-Control-Allow-Origin:\ * rspadd Access-Control-Max-Age:\ 31536000 rspadd Access-Control-Allow-Credentials:\ true rspadd Access-Control-Allow-Headers:\ Accept,\ Authorization,\ Cache-Control,\ Content-Type,\ Content-Md5,\ DNT,\ If-Modified-Since,\ Keep-Alive,\ Origin,\ User-Agent,\ X-Mx-ReqToken,\ X-Requested-With,\ X-Amz-Date,\ X-Amz-User-Agent,\ X-Amz-Acl,\ X-Amz-Copy-Source rspadd Access-Control-Allow-Methods:\ POST,\ GET,\ OPTIONS,\ PUT,\ DELETE server ceph-1 10.0.100.68:7480 check server ceph-2 10.0.100.69:7480 check server ceph-3 10.0.100.70:7480 check backend cors_headers # (2) 这个backend没有设置后端服务器,所以会触发服务器的503错误 rspadd Access-Control-Allow-Origin:\ *
file.http:
HTTP/1.1 200 OK Access-Control-Allow-Origin: * Access-Control-Max-Age: 31536000 Access-Control-Allow-Credentials: true Access-Control-Allow-Headers: Accept,Authorization,Cache-Control,Content-Type,Content-Md5,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With,X-Amz-Date,X-Amz-User-Agent,X-Amz-Acl,X-Amz-Copy-Source Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE Content-Length: 0 Cache-Control: private
摘自:https://my.oschina.net/u/1759688/blog/800131
0顶
0 踩
共 0 条评论