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:cors

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


--- 這一行在寫的時候刪掉,上面的兩行空格是必須的 --
相關文章
相關標籤/搜索