I want to set up an nginx server on a vps to reverse proxy to some Minecraft servers that I am hosting and running locally on my home IP. I understand I will need to buy an A record for my domain(I think) Does this also then cone with subdomains? For instance, if I get the website name example.com and a user enters vanilla.example.com will that work and will nginx be able to detect the subdomain that was used? I was considering setting it up like this (Upstream IP and domain name "example" are placeholders for obvious reasons):
stream {
upstream vanillaMinecraft {
server 192.0.2.1:25565;
}
upstream moddedMinecraft {
server 192.0.2.2:25566;
}
server {
listen 25565;
server_name modded.example.com;
location / {
proxy_pass moddedMinecraft;
}
}
server {
listen 25565;
server_name *.example.com;
location / {
proxy_pass vanillaMinecraft;
}
}
}
I have not attempted this yet as Buying domains can get pricy(especially if I wind up needing multiple domain names) however I do have this working by listening on different ports currently by hitting the IP directly. I really want to set up a human readable name though so it's easier for my friends to remember, join, and swap between servers running different modpacks. And advice about this is appreciated, I am very new to high level networking and web stuff. I was hoping someone could tell me if what I am trying to do is even possible before I bite the bullet and spend the money on an A record for my own domain. My current plan is to just point the domain at the nginx reverse proxy. I have found conflicting information implying that either this will work, or I will need to buy each subdomain for nginx to correctly detect the specialized subdomains correctly(aka to not evaluate to the bare domain and be caught by the wildcard case).
example.com
through a registrar you "own" any name "below" it, you don't need to buy anything again at the name level (you may need one or more different certificates though, but those can be free as well). Also, specifically Minecraft clients do use DNSSRV
records, so you can give even just the name itself (apex, not subdomain) and correct clients will land on proper server.