HAProxy Redirect domain to another domain

From Brian Nelson Ramblings
Revision as of 03:57, 25 November 2020 by Brian (Talk | contribs) (Next restart or start the server to start blocking by ip address)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

HAProxy Redirect domain to another domain

From time to time, you may find yourself wanting to redirect a domain to a folder on another domain

You will want to edit the haproxy.cfg file

vim /etc/haproxy/haproxy.cfg

Then add something like the following to the frontend in haproxy.

acl demoredirect hdr_dom(host) -i demofolder.com
acl demoredirect hdr_dom(host) -i www.demofolder.com
http-request redirect location https://briansnelson.com/demofolder/ code 301 if demoredirect

Save and check your configuration

service haproxy check

You are looking for

Configuration file is valid

Next restart or start the server to start redirecting from one domain to another

service haproxy restart/start