Subdomians with one or few purposes
How can I go about making my different subdomains only work for one or few/select features at a time? Let's say that I have a website, game server, and an api all on the same server. How can I make it so that the subdomain only works for that one thing?
A more visual example is like so:
Game -> game.domain.com -> 127.0.0.1:6969
Website -> www.domain.com -> 127.0.0.1:80 & 127.0.0.1:443
API -> api.domain.com -> 127.0.0.1:4000
I'm sorry if this is a super simple question and I just don't know the terms or what to google, but I really appreciate if you can at least just point me in the right direction as all these records and types are so overwhelming and confusing.
14 Replies
You cannot limit the (sub-)domain name itself to a specific service like that.
You can however grab a dedicated IP address for each thing, and restrict the IP address (e.g. using a firewall or so).
Literally changing your visual example to something like:
Game -> game.domain.com -> 192.0.2.123:6969
Website -> www.domain.com -> 198.51.100.80:80 & 198.51.100.80:443
API -> api.domain.com -> 203.0.113.234:4000
ooo, ok. Am I able to have one server with multiple IPs on it or do I need to basically get one machine for every separate thing?
You can have multiple IP addresses on the same machine.
However, with the IPv4 scarcity, I doubt you'll find that many providers, who wants to provide you with a dedicated IPv4 address for a such purpose.
... if any providers at all.
I truthfully don't think so either which is the annoying part, but at least I have an answer and a general idea on what to do to make it work
Considering that we're on the Cloudflare Discord, ... I assume you're using Cloudflare for your website and the API though?
I remember a while ago I was using this nginx-proxy-man thing that did all of that for me. However, I have swapped over to Apache and I moved registrars and I think that is my big problem, is just simply being lost
yes
Move your website and API ("the origin / backend") to operate on IPv6-only.
Cloudflare with the Proxied (:cloudflare:) records will take care of both IPv4+IPv6 to end users.
That way, you''ll only appear to need the IPv4 for the gamers, according to the visual example you've provided.
Woah! That's sick! I'll have to try figure out a way to do that, but I didn't know that was a thing!
With an IPv6 /64 subnet, which is the most commonly given IPv6 subnet size, you'll technically have 18,446,744,073,709,551,616 different IPv6 addresses to play around with.
So with the IPv6-only origin + Cloudflare in front, there are at least some opportunities, to limit the amount of IPv4 addresses needed behind the stage. 😉
Just a quick question, I don't know if you will be able to answer this, but, may as well ask. Would a reverse proxy thing with Apache work or? I remember that's how I did my api.domain.com before, and, well, I accidently purged it and lost all the configs and don't know how to config the records or whatever on cloudflare 💀
Work in regards to avoid multiple IP addresses? No.
You're pointing the (sub-)domain to an IP address, as long as the IP address is listening on one or more ports, that will technically be accessible no matter which domain that is pointing towards the actual IP address.
AH, ok, perfect, thank you!
And most game servers rarely (if ever) know about the (sub-)domain at all - they're typically listening on the IP address, and that's it.
For the reverse proxy stuff, or whatever you put in front of the website + API, it would still require a dedicated IP, if you would like to "restrict" it as shown in your visual example.
Ah, ok, because I just didn't want people who go to www.domain.com to go to domain.com:4000 (api) and vise versa. On top of that, if I have a game server, I thought it'd be cool to have something like, for example, factorio, I can have factorio.domain.com:3580 to join and factorio.domain.com:80 to go to a website with stuff related to the game
Basically just adding scopes to sub-domains. However, armed with the knowledge I know have - thank you - I can google my way to victory! Or so I hope...
Thank you so much!