Reputation: 29
We have setup LB using haproxy for two domain.
How to use haproxy redirect
or http-request redirect
to redirect one domain to another which cotain sub domain.
For example:
aaa.one.ccc.com -> aaa.two.ccc.com
Thanks!
Upvotes: 2
Views: 5974
Reputation: 2003
Below config worked for me for both domain redirection and tcp traffic redirection from one domain-name/IP to another domain perfectly.
global
log 127.0.0.1 local1
maxconn 4096
ssl-default-bind-ciphers TLS13-AES-256-GCM-SHA384:TLS13-AES-128-GCM-SHA256:TLS13-CHACHA20-POLY1305-SHA256:EECDH+AESGCM:EECDH+CHACHA20
ssl-default-bind-options no-sslv3 no-tlsv10 no-tlsv11
defaults
mode http
maxconn 2048
frontend test-plane
bind *:80
# bind *:443 ssl crt /usr/local/etc/haproxy/test.pem
# # 16000000 seconds is a bit more than 6 months
http-response set-header Strict-Transport-Security "max-age=16000000; includeSubDomains; preload;"
acl demoredirect hdr_dom(host) -i dev.test.bi
acl demoredirect hdr_dom(host) -i www.dev.test.bi
http-request redirect location https://developer.test.bi/ code 301 if demoredirect
redirect scheme https if !{ ssl_fc }
mode http
timeout connect 5s
timeout client 5s
timeout server 5s
# default_backend test-plane
#backend test-plane
# redirect scheme https if !{ ssl_fc }
# server developer.test.bi developer.test.bi:443 check inter 5s rise 2 fall 3
# compression algo gzip
# compression type text/css text/html text/javascript application/javascript text/plain text/xml application/json
frontend aqmp_5671
# bind *:5671 ssl crt /usr/local/etc/haproxy/test.pem
bind *:5671
mode tcp
timeout client 3h
timeout server 3h
default_backend aqmp_5671
backend aqmp_5671
mode tcp
server developer.test.bi developer.test.bi:5671 check inter 5s rise 2 fall 3
frontend testserver_4389
bind *:4389
mode tcp
timeout client 3h
timeout server 3h
default_backend testserver_4389
backend testserver_4389
mode tcp
server developer.test.bi developer.test.bi:4389 check inter 5s rise 2 fall 3
Upvotes: 0
Reputation: 719
There is an oneline solution in haproxy.cfg.
301 redirection from aaa.one.ccc.com -> aaa.two.ccc.com
http-request redirect prefix http://aaa.two.ccc.com code 301 if { hdr_dom(host) -i aaa.one.ccc.com }
Note, this can't be in defaults
section, only in frontend
, backend
or listen
.
Upvotes: 3