1

I want to create a Minecraft server and I already have a server that runs multiple Minecraft servers.

I also have an OVH domain and I've created a subdomain with a wildcard.

I want to create subdomains to access each of my Minecraft servers.

For example, I have two Minecraft servers, one with port 25560 and the other with port 25561. My main domain is "example.com" and I want to connect to my first Minecraft server using "server1.example.com:25565", which would redirect to the server running on port 25560. Similarly, I want to connect to my second server using "server2.example.com:25565", which would redirect to the server running on port 25561.

I tried to create a configuration in NGINX Stream module but I can't use the server_name to specify a subdomain.

I think it's possible because I've seen many Minecraft servers with subdomains. What am I doing wrong?

my module-enable/mc.example.com.conf

stream {
     server {
             listen 25565;
             server_name server1.example.com;
             proxy_pass minecraft;
     }

     upstream minecraft {
             server 127.0.0.1:25560;
     }
     server {
             listen 25565;
             server_name server2.example.com;
             proxy_pass minecraft2;
     }

     upstream minecraft2 {
             server 127.0.0.1:25561;
     }
}

EDIT 20/01/2023:

So I tried something else

stream {
     server {
             listen 25565;
             server_name server1.example.com;
             proxy_pass 127.0.0.1:25560;
     }

     server {
             listen 25565;
             server_name server2.example.com;
             proxy_pass 127.0.0.1:25561;
     }
}

But I got this error: "server_name" directive is not allowed here

GFoniX
  • 189
  • 6
  • Make sure you are restarting Nginx. Also, you may want to try putting the local addresses directly into the proxy_pass instead of in an upstream block. – nicholas Jan 18 '23 at 16:13
  • @nicholas I've already done this but it's not working `nginx: [emerg] "server_name" directive is not allowed here` – GFoniX Jan 20 '23 at 08:27
  • Do you really need to use the `stream` block config here ? Because [stream & server_name can't work together](https://stackoverflow.com/questions/45227491/nginx-server-name-inside-stream-block-possible) You should have a look as this example to make it work: https://serverfault.com/questions/820539/how-to-proxy-multiple-tcp-streams-on-one-port-with-nginx/999428#999428 – Pierre Feb 07 '23 at 10:22

1 Answers1

0

You could either setup a BungeeCord server and let players switch servers from within the game or get a second public IP and handle it with another port forwarding. I don't see any more options here.

Noxic
  • 1
  • My both minecraft server run in the same computer. But i can't use subdomain for redirecting minecraft server ? – GFoniX Jan 20 '23 at 08:30
  • No, unfortunately not. `server_name` comes from HTTP because the client is sending this information to the server. TCP itself does not support something like that. See [this thread](https://stackoverflow.com/questions/45227491/nginx-server-name-inside-stream-block-possible) for more information. – Noxic Jan 20 '23 at 12:17
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 22 '23 at 07:38