Unlocking the Benefits of Virtual Hosting: Practical Examples and Gotchas

TJ. Podobnik, @dorkamotorka
4 min readApr 7, 2023

--

So I have a relatively powerful server with about 100 GB of RAM and other useful computing specs. I have started using it more frequently, not just for one project but for multiple projects. Often, I encounter situations where I want to expose something to the public network, such as an application running on Kubernetes, a Certificate Authority, or a simple Caddy website to experiment with mTLS. While I’m fortunate to have several spare public IP addresses, I am still considering different ways to efficiently set up and manage my infrastructure. I decided to give virtual hosting a try, although I had been using it for quite some time without being fully aware of it. I was pleasantly surprised when I learned more about it and why it is necessary.

Giant rack of server machines

Virtual Hosting by Theory

To give you a mere definition of virtual hosting, and then walk you through some practical examples of where you are actually utilizing it:

Virtual hosting is a method of hosting multiple websites on a single physical server.

While the definition is quite general, it doesn’t define how this is achieved. As is usual with networking, there’s no one-size-fits-all solution, rather there are many but actually quite similar.

In this post, we will not only discuss why virtual hosting might be an interesting feature for you to try but also share some of the gotchas I experienced, leaving me wandering in circles until I got my head around it.

Virtual Hosting by Practice

It all started about a year ago when I got a server and decided to deploy my application using MicroK8s Kubernetes. While Kubernetes usually operates on a cluster of nodes, I was interested in seeing how easy it was to get going with the MicroK8s Kubernetes distribution, so I used it even though I was only operating one node.

I could have set up the service with type NodePort or Load Balancer and my job would have been done, but I wanted to make it more “production-alike,” so I deployed it using Ingress. In networking terms, Ingress is basically a combination of a reverse proxy, load balancer, and routing rules in which the Ingress controller operates and distributes the external traffic that comes from the internet into the Kubernetes cluster. By defacto standard, I was using TLS certificates to secure the external traffic to the entry point of my cluster. To give you an example of where virtual hosting would come into play, I could define multiple hosts of potentially different applications in my Ingress resource configuration, and the HTTP/S request that would come into my cluster would check the Host header of the request to determine to which virtual host to forward the request.

A few days later, I wished to deploy a Certificate Authority (CA) using a Small Step on the same server. However, ports 80 and 443 were already taken by my application, and it had nothing to do with my application, so there was no way I could put it behind the ingress. The first option I considered was just to host it on a non-standard port, but that turned out to be inconvenient because a different user that would want to access it would have to type in the port in the URL. The second and better option was to give my machine another public IP. Then it was like operating on a completely independent machine with its own unique IP and port space, so there were no issues there.

Theory and Practice Together

For those of you who already knew a thing or two about virtual hosting beforehand, you may have already distinguished between the three types of how virtual hosting can be achieved:

  • Name-based hosting — This is the example above, where the Ingress distinguished between different virtual hosts based on the Host header in the HTTP request
  • Port-based hosting — multiple services, just each running and bonded to a different port
  • IP-based hosting — a single machine with multiple IPs and consequently, each unique IP has its own port space.

Conclusion

As you may have noticed, I have taken a hands-on approach to explain virtual hosting, drawing from my own experiences. I believe that sharing real-world examples is an effective way to illustrate the practical applications of this technology. If you found this information helpful, I would greatly appreciate your support by giving me a clap.

Thanks for reading! 😎 If you enjoyed this article, hit that clap button below 👏

Would mean a lot to me and it helps other people see the story. Say Hello on Linkedin | Twitter

Do you want to start reading exclusive stories on Medium? Use this referral link 🔗

If you liked my post you can buy me a Hot dog 🌭

Are you an enthusiastic Engineer, who lacks the ability to compile compelling and inspiring technical content about it? Hire me on Upwork 🛠️

Checkout the rest of my content on Teodor J. Podobnik, @dorkamotorka and follow me for more, cheers!

--

--

TJ. Podobnik, @dorkamotorka
TJ. Podobnik, @dorkamotorka

No responses yet