简体   繁体   中英

NGINX port forwarding with subdomain

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM