Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx proxy_pass to Minecraft server

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.

like image 571
leeway Avatar asked Apr 22 '13 01:04

leeway


2 Answers

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
like image 132
MRVDOG Avatar answered Sep 21 '22 16:09

MRVDOG


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.

like image 28
user1600649 Avatar answered Sep 24 '22 16:09

user1600649