Codementor Events

A beginner's guide to on-prem website hosting

Published Dec 01, 2022
A beginner's guide to on-prem website hosting

TLDR; I hosted this website on a ubuntu 22.04 server running on an 8 GB RAM raspberry-pi behind a CGNAT. The traffic is routed via a cloudflare DNS-updating cronjob and nginx-proxy manager.

I started self-hosting stuff in 2021 and liked the idea of having a computer in the cloud with all the power I could ask for (if I had the money to do so...). I self-hosted a blog for my friends and me to write stupid stuff, a journal, a Minecraft server, and a website. All these services were enough to kill my cute little 1 GB ram t2.micro AWS EC2 instance, so I switched to the Azure student plan, where I burned through the free 100 USD credits thanks to my lack of cost management and IaaS experience.

Even though my enthusiasm and excitement about VPS and cloud hosts had ended by then, a few months later, I was recommended some youtube videos by NetworkChuck, an amazing YouTuber who does some cool networking and pi-related stuff. My interest in servers and DevOps was rekindled, thanks to this guy! I read more about the raspberry pi online and thought it would be cool to have a small physical computer running as a server for hosting my web applications and doing other ad-blocking/VPN-related stuff.

Finding a Pi

I started looking for the best pi for my needs as if I had a lot of options. I had heard about the semiconductor shortage before, but this was my first time experiencing it firsthand. I ordered a complete kit from an unauthorized seller based in Bengaluru, which was risky, but they did not disappoint even a little. I received the kit in 3 days and was ready to tinker, thanks to PiBox India and their excellent support! (I also received a free camera module for the pi, which made the unboxing experience even better)

Alternatives?

I didn't get an online VPS provider because the famous ones were too expensive, and the cheap ones were too shady. I just wanted a home server and a dev environment for hosting my stuff, so going for a monthly subscription would've been costlier than a small physical machine I could use forever. My reason for not using an old PC is simply portability, size, and general lack of interest 😛  Not to mention, I can also use the pi as an actual desktop computer or do other IoT stuff.

Getting Started

Holding an SBC in my hand for the first time did feel different, and I was fascinated knowing how powerful the credit-card-sized machine actually is. The kit came with a 32 GB microSD card pre-loaded with 32-bit Raspberry pi OS, which I formatted immediately because I wanted a more hands-on experience with the machine. I loaded it with 64-bit ubuntu 22.04, thanks to their dedicated docs. Next up, I installed docker and portainer, following this video online. I have worked with docker before at internships, so I could figure out most of the stuff myself. I set up Nginx-proxy-manager on port 80 and was ready to go.

... ready to go on localhost only, tho.

Next, I started with what I thought were the most straightforward steps in the process. Just pointing a domain to my public IP address, and voila! I would have a public website. This wasn't the case, though.

As shown above, the public IP address I was shown on popular websites online was actually my ISP's IP address for my locality. This was not the same as the IP address my router showed me. I was confused for a few hours and looked this up online, where I learned about CGNATs.

Bypassing a CGNAT

I knew I could no longer use an ipv4 address because getting a static IP would be expensive, and talking to an Indian ISP was the last thing I wanted to spend my weekend on.

Naturally, switching to ipv6 from ipv4 and AAAA records from A records was the only viable and straightforward solution. The ipv6 address my device was assigned was unique and visible to the internet.

This came with another challenge, though. Ipv6 addresses, by default, are frequently reset according to the DHCP time lease. I did not want to change this behavior, as I was not a networking expert and was skeptical about changing the router settings.

Finally, after tirelessly searching for answers online, I found a simple breakthrough. Some solutions asked people to get a VPS, but I wasn't planning on paying anything extra; plus, this and other options like connecting through a VPN were too complex or lengthy to even consider, not to mention some even introduced a network lag.

Discover and read more posts from Divyansh Singh
get started
post commentsBe the first to share your opinion
Show more replies