Nginx proxy_pass to Minecraft server

leeway picture leeway · Apr 22, 2013 · Viewed 14.1k times · Source

I'm trying to run two Minecraft servers on the same machine on two different ports. I want to reference them based on subdomains:

one.example.com -> <minecraft>:25500
two.example.com -> <minecraft>:25501

I have used nginx for things like this before, but it's not working with Minecraft. It's responding with http status 400. Here is a sample from my log:

192.168.0.1 - - [21/Apr/2013:17:25:40 -0700] "\x02<\x00\x0E\x00t\x00h\x00e\x00s\x00a\x00n\x00d\x00y\x00m\x00a\x00n\x001\x002\x003\x00\x1C\x00t\x00e\x00s\x00t\x00.\x00r\x00y\x00a\x00n\x00s\x00a\x00n\x00d\x00y\x00.\x00i\x00s\x00-\x00a\x00-\x00g\x00e\x00e\x00k\x00.\x00c\x00o\x00m\x00\x00c\xDD" 400 173 "-" "-"

Here is my nginx config:

upstream mine1 {
  server 127.0.0.1:25500;
}
upstream mine2 {
  server 127.0.0.1:25501;
}

server {
  listen 25565;
  server_name one.example.com;

  access_log /var/log/nginx/one.access;
  error_log /var/log/nginx/one.error;

  location / {
    proxy_pass http://mine1;
  }
}
server {
  listen 25565;
  server_name two.example.com;

  access_log /var/log/nginx/two.access;
  error_log /var/log/nginx/two.error;

  location / {
    proxy_pass http://mine2;
  }
}

If I'm reading this correctly, nginx is responding with 400. My guess is the Minecraft client is not sending valid HTTP headers and Nginx is tossing out the request. But I'm totally at a loss. Any help would be appreciated.

Answer

MRVDOG picture MRVDOG · May 3, 2013

try this in your DNS records

A RECORD

Name     one.example.com
Value    <server_ip>
TTL  86400

Name     two.example.com
Value    <server_ip>
TTL  86400

SRV RECORD

Name     _minecraft._tcp.one.example.com
Port     25500
Value    one.example.com

Name     _minecraft._tcp.two.example.com
Port     25501
Value    two.example.com