我试图让HA-Proxy 301redirect一个https域。 我需要:
https://example.comredirect到https://www.example.com
这是我试图让它工作:
# corp - example.com redirect prefix https://www.example.com code 301 if { hdr(host) -i example.com } redirect prefix https://www.example.com code 301 if { hdr(host) -i www.example.com } acl server01 hdr_dom(host) -i www.example.com
我将不胜感激任何帮助!
编辑的cfg文件示例(底部的代码是cfg的一部分):
全球
日志/ dev / log local0
log / dev / log local1通知
chroot / var / lib / haproxy
用户haproxy
组haproxy
守护进程
默认
日志全球
maxconn 100000
模式http
选项httplog
选项dontlognull
选项forwardfor
超时连接600000ms
超时服务器600000ms
超时客户端600000ms
错误文件400 /etc/haproxy/errors/400.http
错误文件403 /etc/haproxy/errors/403.http
错误文件408 /etc/haproxy/errors/408.http
错误文件500 /etc/haproxy/errors/500.http
错误文件502 /etc/haproxy/errors/502.http
错误文件503 /etc/haproxy/errors/503.http
错误文件504 /etc/haproxy/errors/504.http
前台main_http_proxy
绑定*:80
模式http
http-request add-header X-Forwarded-Proto https if {ssl_fc}
统计启用
stats uri / haproxystatus?stats
统计领域Strickly \ Private
stats auth ec2ops:7is92kc81k92kds8
# example.com #redirect scheme https code 301 if { hdr(host) -i www.example.com } !{ ssl_fc } #redirect prefix https://www.example.com code 301 if { hdr(host) -i example.com } !{ ssl_fc } #redirect prefix https://www.example.com code 301 if { hdr(host) -i example.com } #redirect prefix https://www.example.com code 301 if { hdr(host) -i www.example.com } acl no_WWW hdr(host) -i example.com redirect prefix www.example.com code 301 if no_WWW # Backend Rules use_backend SERVER01 if jcma01 use_backend SERVER01 if no_WWW
前端main_https_proxy
bind :443 ssl crt / etc / haproxy / pem /
模式http
http-request add-header X-Forwarded-Proto https if {ssl_fc}
acl secure dst_port eq 443
rsprep ^ Set-Cookie:\(。 )Set-Cookie:\ \ 1; \如果安全,则为Secure
rspadd Strict-Transport-Security:\ max-age = 31536000(如果安全)
use_backend SERVER01 if { ssl_fc_sni www.example.com } #use_backend SERVER01 if { ssl_fc_sni example.com }
后端server01平衡源cookie SERVER01插入服务器SERVER01 10.10.10.10:80 cookie SERVER01检查inter 5s
不知道你得到那些ACL,不会
redirect scheme https code 301 if !{ ssl_fc }
要么
redirect scheme https code 301 if {hdr(host) -i yourdomain.example.com } !{ ssl_fc }
成为更清洁的解决scheme