我有HAProxyconfiguration与一个单一的前端接受HTTP和HTTPS连接。 所有的后端只有HTTP。
我想强制某些path使用HTTPS(/ Login等),以便HAProxy在HTTP上接收请求时为这些path返回一个redirect。
我去了以下完美的作品在我的情况下:
frontend yadayada ... acl Secure dst_port 443 acl Login path_beg /login redirect scheme https code 301 if Login !Secure
对于以/ Login结尾的URI,path_end可能是最恰当的:
https://stackoverflow.com/questions/20606544/haproxy-url-based-routing-with-load-balancing
然后你的configuration会看起来像这样(不完整,为了说明)。
frontend http acl secure path_end -i /Login #matches path ending with "/Login" use_backend secure_server if secure backend secure_server redirect scheme https if ! secure