The main challenge to hosting a website on the local machine is a dynamic IP address, which keeps changing. We can buy static IP address, but it’s expensive compared to regular internet service and unnecessary for everyday users.
Let’s explore how to mitigate it.
- There is a service that maps your dynamically changing IP address to a domain name. NoIP is one of the popular services for this. NoIP provides a free account for one domain with limited function, but it’s enough for a hobby project. Once you register your account, you can select a domain name among the free options. I guess it’s possible to map a custom domain as well. I haven’t tested, though.
- After that, you need to set up a way to send a new IP address to NoIP once it’s changed. This can be done by two ways.
- Your router may support the Dynamic DNS (DDNS) feature. In my case, the TP-Link router provided this feature. I could register the NoIP username, password in the router. The router will send the latest IP address to NoIP when it’s changed.
- If your router does not support this feature, you can download and install the application that NoIP provides. The application sends IP address changes to NoIP.
- Now your domain is linked to your IP address. If you type in the domain name in a web browser, it will open your router admin page because the entry point of the home internet is 192.168.1.1 which is set to the router admin web page. Up to this far, you can control your router setting if this is what you want.
- But, to host a website, we must pass through the connection from the domain name to a destination server, probably PC or Raspberry Pi. NAT Forwarding or Port Forwarding ( or Virtual Server) feature in the router admin will do the job. You can select protocol, HTTP, and port, 80, and destination internal IP address where your web site is running.
- In my case, I have 2 routers. One simple router is connected to the modem and linked to the other mesh router, which distributes the internet to all home devices. So, I also had to configure Port Forwarding in the second router. It worked well.
- Now, if I access http://moneystock.ddns.net, which lands on my web server, actually an old laptop.
This experience has been inspired by Self hosting in 2023
I have wanted to host a website at home for a long time. In 2023, it turns out that it is 20 minutes job.