1
global
        log         127.0.0.1 local2
        chroot      /var/lib/haproxy
        pidfile     /var/run/haproxy.pid
        maxconn     4500
        user        haproxy
        group       haproxy
        daemon
defaults
        mode                    tcp
        log                     global
        retries                 8
        timeout connect 10s
        timeout server 10s
        timeout client 10s

frontend 0
    bind *:25565
        mode tcp
        acl test hdr(host) -i test.mydomain.com
        use_backend 0 if test
backend 0
    mode tcp
        server node0 22.28.29.28:25585 check

Hello,

I'm trying to use haproxy for my Minecraft server. What I want is a config that I can just add more subdomains and what IPs they proxy to. The issue I'm having is when you try to connect it just says "Logging in..." than says "Disconnected". Am I doing anything wrong?

I also have *.mydomain.com pointing to my haproxy server.

Thanks :)

chicks
  • 3,639
  • 10
  • 26
  • 36
someguy9999
  • 11
  • 1
  • 2
  • 1
    The answer from @chicks is 100% correct... *unless* you are feeling extremely clever and aren't afraid to do some work. The minecraft client/server protocol appears to be "client talks first" and the server name seems to be sent in-band... so it *should* be possible to configure HAProxy to inspect the bytes in the payload of that first packet and select the back-end accordingly... but this is a fairly advanced undertaking, as you have to identify exactly which bytes mean what, and configure HAProxy at a very low "close to the wire" level. – Michael - sqlbot Nov 05 '15 at 03:01
  • 1
    @Michael-sqlbot `mode minecraft` as a patch for haproxy would be epic. – chicks Nov 05 '15 at 03:09
  • lol @chicks. Actually, it may not be too tricky if we go for a fairly lazy approach based on what I have found of protocol docs... If I could get someone with a minecraft server to try this in the frontend block: `tcp-request inspect-delay 5s` and `use-backend my_backend_name if { req.payload(0,0),lower -m sub thesubdomain.example.com }` "my_backend_name" would be the name of the back-end, which is "0" in this question. The `use_backend` line would be repeated for each possible matching hostname/back-end combo. – Michael - sqlbot Nov 05 '15 at 11:17

2 Answers2

2

Any header-based functionality won't work for minecraft since TCP-mode doesn't look for any headers. Hosting multiple minecraft servers is usually done by using unique ports. The other easy choice is multiple IP's. If you want to go with multiple ports then you would need to create a frontend for each listening port in haproxy.

chicks
  • 3,639
  • 10
  • 26
  • 36
1

Your ACL is never going to match in mode tcp, since you're checking a layer7 functionality.

Change both occurrences of mode to http and you should be good.

GregL
  • 9,030
  • 2
  • 24
  • 35
  • but [minecraft connections are not http](http://minecraft.gamepedia.com/Tutorials/Setting_up_a_server#Port_forwarding) so that won't work – chicks Nov 04 '15 at 22:09
  • 1
    Well, that's a whole other story then and your answer is much more fitting. – GregL Nov 05 '15 at 00:08