How to Use HAProxy with a Minecraft Server
Learn how to configure HAProxy as a TCP load balancer and reverse proxy for your Minecraft server network, including health checks and failover.
Why Use HAProxy for Minecraft?
HAProxy is a high-performance TCP and HTTP load balancer used by some of the largest websites in the world. For Minecraft, haproxy minecraft server setups serve two main purposes: distributing player connections across multiple proxy instances, and hiding your backend server IPs from public view. If you run a multi-proxy network, HAProxy can balance load and provide automatic failover when a proxy goes down.
Installation
On Ubuntu or Debian:
sudo apt update
sudo apt install haproxy
On CentOS or RHEL:
sudo yum install haproxy
Verify the installation with haproxy -v. You want version 2.4 or newer for the best protocol support.
Basic Configuration
Edit /etc/haproxy/haproxy.cfg. Below is a working configuration for a haproxy minecraft server deployment with two Velocity proxies:
global
log /dev/log local0
maxconn 4096
user haproxy
group haproxy
daemon
defaults
log global
mode tcp
option tcplog
timeout connect 5s
timeout client 30s
timeout server 30s
frontend minecraft_front
bind *:25565
default_backend minecraft_proxies
backend minecraft_proxies
balance roundrobin
option tcp-check
server proxy1 10.0.0.10:25577 check inter 5s fall 3 rise 2
server proxy2 10.0.0.11:25577 check inter 5s fall 3 rise 2
Key Settings Explained
- mode tcp: Minecraft uses raw TCP, not HTTP. Always use TCP mode.
- balance roundrobin: Distributes new connections evenly. You can also use
leastconnto send players to the proxy with fewer active connections. - check inter 5s: HAProxy pings each backend every 5 seconds. If a proxy fails 3 checks in a row (
fall 3), it is marked as down. - timeout client/server: Set to 30 seconds minimum. Players who idle might get disconnected if this is too low. For AFK-friendly servers, increase to 300s or more.
PROXY Protocol Support
By default, your Velocity proxies see HAProxy's IP instead of the player's real IP. To fix this, enable the PROXY protocol. Add send-proxy-v2 to each server line:
server proxy1 10.0.0.10:25577 check send-proxy-v2
Then in your Velocity velocity.toml, enable PROXY protocol:
haproxy-protocol = true
Now your haproxy minecraft server setup preserves real player IPs through the entire chain.
Monitoring
Enable the HAProxy stats page by adding to your config:
listen stats
bind *:8404
mode http
stats enable
stats uri /stats
stats auth admin:your-secure-password
Visit http://your-server:8404/stats to see live connection counts, backend health, and traffic rates. Protect this endpoint with a strong password and firewall rules.
Failover Behavior
When a proxy goes down, HAProxy stops sending new connections to it within seconds. Existing connections on the failed proxy are lost (players get disconnected), but new players automatically connect to healthy proxies. For even smoother failover, pair this with RedisBungee so player sessions are shared across proxies.
A haproxy minecraft server setup is ideal for networks that need professional-grade load balancing without paying for a managed service. Combined with proper DDoS protection, it forms a strong front line for your infrastructure.
Need a proxy-ready network? Astroworld Hosting supports Velocity, BungeeCord, and multi-server setups on every plan.