HAProxy Redirect domain to another domain

From Brian Nelson Ramblings
Revision as of 06:56, 21 October 2020 by Brian (Talk | contribs) (Created page with "==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 th...")

(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 blocking by ip address

service haproxy restart/start