Skip to main content

Forced Hosts Configuration

ForcedHosts allows you to route players to specific backend servers based on the hostname they use to connect to your Gate proxy. This enables multiple domains to point to the same proxy but direct players to different servers.
ForcedHosts is available in classic mode (when lite.enabled: false). For lightweight deployments, see Gate Lite Mode which provides similar host-based routing with advanced load balancing.

How It Works

When a player connects to your Gate proxy, the client sends the hostname they used in the initial handshake packet. Gate examines this hostname and routes the player based on your ForcedHosts configuration.

Configuration

object
Map of hostnames to server name lists. Keys are hostnames (case-insensitive), values are arrays of server names for load balancing.

Key Features

Hostname-Only Matching

Port numbers are ignored - creative.example.com:25565 matches creative.example.com

Case-Insensitive

Creative.Example.COM matches creative.example.com

Load Balancing

List multiple servers per hostname for distribution

Automatic Fallback

Uses try list when no forced host matches

Basic Configuration

Simple Domain Routing

Route different domains to different game modes:
config.yml

Load Balancing Setup

Distribute players across multiple servers for the same hostname:
config.yml
Gate tries servers in order from the list. For advanced load balancing strategies (random, round-robin, least-connections), use Gate Lite mode.

Advanced Examples

Multi-Domain Network

Support multiple domains and aliases for a large server network:
config.yml

Development and Production

Separate development and production environments:
config.yml

Mixed Load Balancing Strategy

Combine load balancing with single servers:
config.yml

DNS Configuration

For ForcedHosts to work, configure DNS records to point all domains to your Gate proxy IP:

Behavior and Matching

Understanding how Gate matches hostnames:

Matching Rules

  1. Port Ignored - example.com:25565 matches example.com
  2. Case Insensitive - Example.COM matches example.com
  3. Exact Match - No wildcard or regex support
  4. Virtual Host Cleaning - Handles Forge FML separators automatically
  5. IP Addresses - Raw IP connections don’t match, use try list

Connection Examples

Given this configuration:
How different connections are routed:

Forge/FML Handling

Forge clients append \x00FML\x00 to virtual host. Gate automatically strips this before matching:

Load Balancing Behavior

When multiple servers are listed for a hostname:
Gate tries servers in order:
  1. Attempts connection to lobby-1
  2. If lobby-1 is offline or fails, tries lobby-2
  3. If lobby-2 is offline or fails, tries lobby-3
  4. If all fail, uses try list or disconnects player
This is sequential failover, not random load balancing. All players go to first available server. For true load balancing (random, round-robin, least-connections), use Gate Lite mode.

Complete Example

A full configuration for a multi-server network with forced hosts:
config.yml

Troubleshooting

Problem: Players connecting to creative.example.com end up on wrong serverDiagnosis:
  1. Enable debug logging: debug: true
  2. Check logs for hostname Gate receives
  3. Verify DNS points to Gate proxy
  4. Test with /connect creative.example.com (if different result, it’s DNS)
Common Causes:
  • DNS not pointing to Gate
  • Hostname mismatch (check case, spacing)
  • Server name in forcedHosts doesn’t exist in servers section
  • Player connecting via IP address instead of domain
Problem: All players go to same server despite multiple listedExplanation: This is expected - Gate uses sequential failover, not random distributionSolution: For true load balancing, use Gate Lite mode with load balancing strategies:
Problem: Players connecting via IP address don’t get routedExplanation: This is expected - ForcedHosts only work with domain namesSolutions:
  • Encourage players to use domain names
  • Configure try list as your “default” routing
  • Block IP connections: set server-ip=127.0.0.1 on Gate bind
Error: Forced host "creative.example.com" server "creative" must be registered under serversSolution: Add server to servers section:
Problem: Players get disconnected when hostname doesn’t matchDiagnosis:
  • Check try list is configured with available servers
  • Verify servers in try list exist in servers section
  • Check if servers in try list are actually online
Solution:

Migration from Broken Configs

If you configured ForcedHosts before it was fixed (PR #560), your configuration should now work automatically! The fix included proper hostname extraction, case normalization, and fallback behavior.
No changes needed - existing forcedHosts configurations will work after updating Gate.

Comparison: ForcedHosts vs Gate Lite

For advanced routing and load balancing, consider Gate Lite mode.

Best Practices

Choose clear, memorable hostnames:
  • creative.example.com, survival.example.com
  • s1.example.com, server2.example.com
Always have reliable fallback servers in try list for unmatched hostnames or IP connections:
Keep documentation of which domains route where. Add comments:
After configuration changes, test each hostname:
If using wildcard DNS (*.example.com), remember all subdomains will resolve. Consider:
  • Adding explicit forcedHosts for intended subdomains
  • Having good default try list for unmatched subdomains

Servers

Configure backend servers and try list

Gate Lite Mode

Advanced host-based routing with load balancing

Forwarding

Forward player info to backend servers

Status Ping

Customize server list appearance per hostname