당신이 HAProxy 1.5을 사용하고 최대이 작업을해야하는 경우에 당신
단일 도메인 : (더러운하지만 작동)
# match non www requests:
acl has_www hdr_beg(host) -i www.
# add a header that says we need to redirect these type of requests (will explain later)
http-request add-header X-Host-Redirect yes unless has_www
# rule to identify newly added headers
acl www_redirect hdr_cnt(X-Host-Redirect) eq 1
# where the magic happens (insert www. in front of all marked requests)
reqirep ^Host:\ (.*)$ Host:\ www.\1 if www_redirect
# now hostname contains 'www.' so we can redirect to the same url
redirect scheme http if www_redirect
:
acl has_www hdr_beg(host) -i www
redirect prefix http://www.example.com code 301 unless has_www
여러 도메인 새 헤더를 추가하는 이유는 HAProxy 1.5 이상에서 ACL이 bei 각 참조에 대해 평가되었습니다. 그래서 새로운 헤더없이 이것을하려고 할 때 :
#catch all domains that begin with 'www.'
acl has_www hdr_beg(host) -i www.
#insert www. in front of all non www requests
reqirep ^Host:\ (.*)$ Host:\ www.\1 unless has_www
#now hostname contains 'www.' so when the next rule gets interpreted it does not match then fails
#redirect to new url
redirect code 301 prefix/if has_www
희망이 도움이 될 것입니다. 나는 HAProxy 1.5에 5 개 개의 다른 도메인으로이 테스트를했는데 그것은 잘 작동하고 경로 및 쿼리 매개 변수를 보존 리디렉션하는 HAProxy 1.6 리디렉션
어떤 버전의 HAProxy를 사용하고 있습니까? –