# Anyone have any experience with HAproxy?

**URL:** https://meta.discourse.org/t/anyone-have-any-experience-with-haproxy/29560
**Category:** Self-hosting
**Tags:** docker
**Created:** [June 2, 2015, 4:32pm UTC](https://meta.discourse.org/t/anyone-have-any-experience-with-haproxy/29560 "2015-06-02T16:32:55Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)
#### Post date: [June 2, 2015, 4:32pm UTC](https://meta.discourse.org/t/anyone-have-any-experience-with-haproxy/29560/1 "2015-06-02T16:32:55Z")

</div>

I’ve installed Docker on my server and it seems to be working fine, however I already have several sites on this Apache server and I read that we should avoid mod\_proxy and use HAproxy instead - but I am unsure how to proceed.

Is it possible to have HAproxy direct all traffic for a specific domain (the Discourse docker container) to a specific port, then everything else as normal?

Any help in getting this configured would be appreciated :- )

---

<div class="post-metadata">

### Author: ![mac](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mac/32/42876_2.png) [@mac](https://meta.discourse.org/u/mac)
#### Post date: [June 2, 2015, 4:45pm UTC](https://meta.discourse.org/t/anyone-have-any-experience-with-haproxy/29560/2 "2015-06-02T16:45:08Z")

</div>

You want to filter for that domain on the defined front end, and then ensure it routes to whatever port you want to use on the back end. HAproxy is (in my opinion) completely awesome and deserves a deeper dive because it can be useful for so much more than just web services.

This should give you a solid starting point:  
[http://seanmcgary.com/posts/haproxy—route-by-domain-name](http://seanmcgary.com/posts/haproxy---route-by-domain-name)

---

<div class="post-metadata">

### Author: ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)
#### Post date: [June 3, 2015, 1:20am UTC](https://meta.discourse.org/t/anyone-have-any-experience-with-haproxy/29560/3 "2015-06-03T01:20:34Z")

</div>

Thanks @macsmith71

Does the config below look ok to you? Am I right in thinking that if something doesn’t match the acl, it will default to the `default_backend`?

```
global
    # to have these messages end up in /var/log/haproxy.log you will
    # need to:
    #
    # 1) configure syslog to accept network log events. This is done
    # by adding the '-r' option to the SYSLOGD_OPTIONS in
    # /etc/sysconfig/syslog
    #
    # 2) configure local2 events to go to the /var/log/haproxy.log
    # file. A line like the following can be added to
    # /etc/sysconfig/syslog
    #
    # local2.* /var/log/haproxy.log
    #
    log 127.0.0.1 local2

    chroot /var/lib/haproxy
    pidfile /var/run/haproxy.pid
    maxconn 4000
    user haproxy
    group haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

defaults
    mode http
    log global
    option httplog
    option dontlognull
    option http-server-close
    option forwardfor except 127.0.0.0/8
    option redispatch
    retries 3
    timeout http-request 10s
    timeout queue 1m
    timeout connect 10s
    timeout client 1m
    timeout server 1m
    timeout http-keep-alive 10s
    timeout check 10s
    maxconn 3000

frontend http-in
        bind *:80
        default_backend main-apache-sites
		
        # Define hosts
        acl host_discourse hdr(host) -i my-discourse-site.com

        # figure out which one to use
        use_backend discourse_docker if host_discourse
		

backend main-apache-sites
    server server1 127.0.0.1:8080 cookie A check

backend discourse_docker
    server server1 127.0.0.1:8888 cookie A check

```

---

<div class="post-metadata">

### Author: ![mac](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mac/32/42876_2.png) [@mac](https://meta.discourse.org/u/mac)
#### Post date: [June 3, 2015, 3:29pm UTC](https://meta.discourse.org/t/anyone-have-any-experience-with-haproxy/29560/4 "2015-06-03T15:29:28Z")

</div>

Sorry, didn’t see this until now.  
The site stuff looks ok, but if you want to chroot you need to set the pid  
and log to write into the chroot. Or comment out the chroot line. I will go  
over it more closely when I get home later this afternoon.

---

<div class="post-metadata">

### Author: ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)
#### Post date: [June 3, 2015, 4:01pm UTC](https://meta.discourse.org/t/anyone-have-any-experience-with-haproxy/29560/5 "2015-06-03T16:01:09Z")

</div>

Thanks Mac.

Do you think I should just use the config as per the link you posted? (I just thought that as the post is a couple of years old the default config with the install might have been better/newer.)

---

<div class="post-metadata">

### Author: ![mac](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mac/32/42876_2.png) [@mac](https://meta.discourse.org/u/mac)
#### Post date: [June 3, 2015, 4:49pm UTC](https://meta.discourse.org/t/anyone-have-any-experience-with-haproxy/29560/6 "2015-06-03T16:49:37Z")

</div>

They go really slow as far as major version releases. Its entirely possible  
that a config doesn’t have formatting or variable changes for a couple of  
years. Are you playing with 1.5 or 1.6? I would keep your config, just  
maybe comment out the chroot directive to make sure the site stuff works,  
then double back to dial in the chroot pathing until that also works.  
Shouldn’t be too bad.

---

<div class="post-metadata">

### Author: ![AstonJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/astonj/32/215041_2.png) [@AstonJ](https://meta.discourse.org/u/AstonJ)
#### Post date: [June 4, 2015, 12:44am UTC](https://meta.discourse.org/t/anyone-have-any-experience-with-haproxy/29560/7 "2015-06-04T00:44:51Z")

</div>

Good news and bad news.

Good news is that Discourse seems to be working fine. Bad news is that all my other sites are broken. (Seems to be an issue with Virtualmin), I’ve reverted for now, will look more into it and try again tomorrow. Any ideas in the meantime would be appreciated!
