this post was submitted on 21 Oct 2024
27 points (96.6% liked)

Linux

48461 readers
510 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

Hi there, I will preface this by saying that I'm brand new to server stuff. I have used Linux for a very long time as a personal desktop computer, but not as a server exposed to the internet. I've previously only hosted Minecraft servers for my friends and also once had a VPS for a Discord bot, but otherwise never touched servers.

I've bought a VPS and domain name (let's call it domain.com) and have spun up a Nextcloud instance with it, currently at cloud.domain.com. It's all working smoothly and I'm happy with it.

I wanted to use this VPS to host multiple services. Currently wanting to self-host the following:

  • Mail server
  • Mastodon instance
  • Matrix server
  • Static website (on domain.com)
  • Forgejo instance
  • Possibly other miscellaneous things I might want to put on it, but that's what I'm planning for now

Now this is where the noob question comes in. I want to use this same VPS to host these services, probably as Docker containers, under subdomains like mail.domain.com, mastodon.domain.com, matrix.domain.com, etc, with the root domain being used to host my static website. Is it possible to do this all on one VPS? What about all on one IP address just using different ports? e.g. could I have mastodon.domain.com pointing to the same IP address as cloud.domain.com but just a different port? How do I set up the DNS records to do this?

Currently I have an A record at domain.com pointing to my VPS's IP address (so I can ssh into it with ssh 0v0@domain.com) and a CNAME record at cloud.domain.com pointing to domain.com. This was kind of a complete guess as to how to set this up as this is my first time managing a domain name and I didn't know anything about DNS records before doing this. It seems to work with my current setup of just using the VPS for Nextcloud but obviously I want to do more with this VPS, either that or I'd like to reduce the specs of this VPS to save money as I picked an option that I imagined would be capable of hosting all these things. Is it possible to set up DNS records such that when you connect to subdomain.domain.com it connects you to a specific port? Or is that not something DNS records can do, but I can set up server-side on my VPS?

My VPS provider also lets me buy additional IPv4 addresses for the VPS, if I can't have them on the same IP address with different ports should I buy more IP addresses instead? How do I go about using different IP addresses for the same server?

Or do I need to host these services on completely different VPSes and point towards the different IP addresses with A records?

I've also heard of reverse proxies and that they might be able to achieve this, is this something I should look into or am I barking up the wrong tree here?

I know this question betrays a complete lack of knowledge as to how networking works, so please bear with me. Before someone says "well if you don't know this, you shouldn't be hosting all these services", I have been finding the experience so far (i.e. just having set up my server with Nextcloud) to be fun and educational. I learn best by doing (I have ADHD and struggle with just reading books without doing any exercises alongside it) and I'd like to try host all these services just for the sake of the experience. I'm not hosting anything critical, it is purely for personal projects and I plan to have my friends on my Mastodon and Matrix servers. If this were for something serious I agree I'd get it managed by a professional sysadmin or at least someone who knows what they're doing, but this is just for fun.

I don't need my hand completely held, like I don't need a step by step, but if I could at least be pointed towards concepts/things to research to achieve what I want, I would appreciate that. Literally if I could just be told search terms to look up that would be great, or if you have any more specific pointers than that with specific articles etc even better, or just explain on a high level how I would achieve this setup. Thanks in advance for any help!

TLDR: Is it possible to host these different services on one VPS with one IP address on different ports? If so, how do I set up the DNS records accordingly with my subdomains? If not, how should I achieve hosting these different services on different subdomains, preferably on the same VPS if at all possible?

Edit: Thank you for all the responses, sorry I couldn't give everyone an individual response, but I'm grateful for all the help. I'll look into reverse proxies :) Appreciate it!

you are viewing a single comment's thread
view the rest of the comments
[–] e0qdk@reddthat.com 4 points 1 month ago

You can do this by configuring an HTTP server (e.g. Apache) to listen on port 80 and/or 443 (HTTP and HTTPS standard ports, respectively) and select which site to serve based on the name of the site requested. Apache documentation for this feature is here: https://httpd.apache.org/docs/2.4/vhosts/name-based.html

Note the sample config snippet showing how to set up a simple static site serving both www.example.com and other.example.com using ServerName in a VirtualHost to select between them.

You can also have Apache match a pattern in the URL and reverse proxy to another HTTP server -- that can just be another program on the same computer listening on a different port, or could be on another computer entirely. See the simple reverse proxy config example on this page for a starting point: https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html (Note also that you probably don't need anything further down that page -- e.g. the load balancer and failover stuff is not likely to be useful to you for a small personal project.)

Other popular HTTP servers can do this too; I just happen to have done it with Apache before.