10

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.

leeway
  • 485
  • 1
  • 3
  • 9

4 Answers4

14

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
MRVDOG
  • 1,717
  • 2
  • 13
  • 20
  • While I myself understand the idea here, what value is there in doing a dns based round robin? How would this work over say dnat/snat-ing the traffic from an bastialion server? – Dwight Spencer Dec 14 '14 at 23:22
  • This isn't dns round robin, this is how minecraft handles sub domains in srv records. – Ryan Leach Jul 03 '17 at 07:28
5

As Dag Nabbit stated, a Minecraft server does not talk http. You would typically do this via NAT. A proxy server needs to know the protocol, because as the name suggests, it acts on behalf of the the client. Nginx knows various protocols, not just http, but Minecraft is not one of them. You can however write a proxy module for this protocol and use the existing nginx infrastructure. Since I'm not familiar with the protocol, I can't comment on the fact that this would have any advantages over NAT.

  • Thanks. I'll try to get the NAT working, but doesn't that require multiple IP addresses? – leeway Apr 24 '13 at 23:18
  • @leeway No, it doesn't. You can do routing on your own server itself, i.e. set a NAT rule locally that says to route all data coming into that server to a different port. Ultimately you do this at your border firewall and/or router, but it is possible to do it locally. – Thomas Ward Oct 24 '14 at 17:12
0

One thing to note for future readers, while yes nginx does pass connections off as a "proxy" to any server:port listing that is defined though the upstream definition in a socks proxy style of connection. This does not work when nginx itself is listening for HTTP communications. This is simply because nginx is is designed by default as a dead simple static http server.

Any sort of reverse proxing of TCP/UDP connections is more scalable at a lower OSI level (ie layer 3 or layer 2 instead of layer 6/7 as nginx is operating at). This is where Source and Destination NATs come into play which is better handled by a firewall or routing policy directive of your edge device.

DNS-RR is not the best solution as this, while yes lower level OSI layering, is only viable if the end applications (layer 7 OSI) understand the method. Minecraft (or just about any game server) at last check did not have this built into the game's networking code.

Now I did look into this and there is a few solutions for minecraft itself that one should look further into:

  • Transporter plugin
  • BungeeCord

Be sure to read all the documentation as these are very complex to configure and install. Hench the recommendation to just use NAT-ed network topology instead.

Dwight Spencer
  • 1,472
  • 16
  • 22
-1

I tried to setup my multiple minecraft instances with SRV but that also doesn't work nslookup of my srv records show:

C:\Users\Administrator>nslookup -type=SRV _minecraft._tcp.xxx.net Server: mijnmodem.kpn Address: 192.168.1.1

Non-authoritative answer:

  1. _minecraft._tcp.xxx.net SRV service location:

      priority       = 5
      weight         = 5
      port           = 25565
      svr hostname   = camelot.xxx.net
    
  2. _minecraft._tcp.xxx.net SRV service location:

      priority       = 5
      weight         = 5
      port           = 25566
      svr hostname   = cityworld.xxx.net
    

On my router(ZTE H369) port 25565 and 25566 are straight forwarded (TCP and UDP) to the IP wher the instances run. Accessing the urls (in Minecraft) gives io.netty.channel.Abstart$AnnotatedConnectException

Any suggestions how to investigate further?

Diverking
  • 11
  • 1
  • It looks like you have a separate, related question to OP. Please refrain from leaving additional questions as answers, and instead open a new question and reference this one, if you think it provides additional context. You can read more about SO question/answer etiquette [here](https://stackoverflow.com/help/deleted-answers). – superhawk610 Mar 22 '21 at 21:39