I own one domain like xyz.com and I'm trying to redirect subdomain other ip with haproxy.

I use tomcat on the servers and I use haproxy to redirect incoming requests on port 80 to port 8080.


www.xyz.com ->

www.xyz.com/abc ->
  or  abc.xyz.com ->

In order to do this redirection, how do I set haproxy?

  • 4
    I don't know why you got downvoted 3 times and without any comment. This is not a very good stackexchange etiquette! Sorry for this bad welcome.
    – Stefano
    Jan 23, 2012 at 10:42

2 Answers 2


In haproxy you do redirection combining acl rules and redirect ones; you choose the right server using the backend rule.

The official haproxy documentation is not very easy to read, but it's very complete.

Something like this (just a sketch to give you an idea):

frontend http-in
    mode              http
    bind              FRONTENDIP:80 # eg.

    default_backend   tomcat_server_2

    acl tomcat_1      hdr_end(host) -i www.xyz.com
    acl tomcat_2      hdr_end(host) -i abc.xyz.com
    acl tomcat_path   path_beg /abc/

    use_backend       tomcat_server_1 if tomcat_1 !tomcat_path

backend tomcat_server_1
    server tomcat1 maxconn 1000

backend tomcat_server_2
    server tomcat2 maxconn 1000

If you want to redirect www.xyz.com/abc/ to abc.xyz.com :

    redirect prefix   http://abc.xyz.com if tomcat_path
  • 1
    Thanks for the example! I think the second backend tomcat_server_1 should be backend tomcat_server_2
    – redgeoff
    Jul 26, 2017 at 22:33
  • doesn't work. It is putting it on the end instead of the prefix. Mar 3, 2021 at 19:47

Haproxy is neither meant to redirect names nor to redirect URIs.

Names are directed by name servers (DNS).

URIs are redirected by (modules of) a webserver (HTTP).

Haproxy is to balance traffic (TCP/IP) between two (or more) identical servers.

  • 8
    haproxy can very well redirect both prefixes (subdomain/domain/etc.) and urls. Search for redirect location and redirect prefix in haproxy.1wt.eu/download/1.4/doc/configuration.txt
    – Stefano
    Jan 23, 2012 at 10:41
  • 8
    You 're wrong, Haproxy is both a load balancer and a reverse proxy server.
    – jmoreira
    Jul 11, 2014 at 2:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.