Advertisements

How to host multiple websites from home

A website is a collection of related web pages, including multimedia content, that people can access anytime from anywhere of the Internet.

A website facilities the exchange of information between multiple parties. For instance, when you read the content of this page, I would have, hopefully, share the information of how to host multiple websites from home.

With the proliferation of single board computers, it is now inexpensive to deploy computing devices to serve different purposes at home. If you do not switch off your Internet modem at home, you may want the option of accessing some of these devices when you are away from home. For instance, the following is a list of device applications that you may want to access from outside your home network:

Each of these hosted applications can be seen as a website.

A typical network architecture for hosting multiple websites at home could look like the following:

Home network architecture

This post documents some procedures that we can follow in order to host multiple websites from home. The procedures are based on the assumption that the public IP address of your home router do not change when you do not switch it off.

Allocating one domain name for each website

A domain name is usually an easy-to-remember name that maps to hard-to-remember IP addresses for the web client to contact a web server. As mentioned in my post on the reverse proxy server, when we only have one public IP address, we will need a way for our reverse proxy server to recognise HTTP requests designated for different upstream servers who are serving the websites or web applications.

One effective way will be to use one domain name for each website. For example, I could allocate cctv1.techcoil.com for a Raspberry Pi 3 CCTV camera, cctv2.techcoil.com for a Raspberry Pi Zero W CCTV camera and pymvp.techcoil.com for my Python Flask Minimal Viable Product.

Setting up a reverse proxy server

Once we had allocated one domain name for each of our websites, we can set up the reverse proxy server to handle the requests made to those domain names. Since Raspberry Pi 3 is quite affordable, we can setup a reverse proxy server with nginx, Raspbian and Raspberry Pi 3.

Sitewide-10usd468x60

Creating network address translation rules to map port 80 and 443 of router's public IP address to reverse proxy server's private IP address

To allow for multiple devices to access the internet, most of us probably have a router sitting behind the modem given by our Internet Service Provider. Most of the home routers available in the market allow the creation of network address translation rules to map certain ports of the router's public IP address to a private IP address.

If you own a Linksys EA7500 Max-Stream AC1900 router, this is how you can create the network address translation rules to map port 80 and 443 of router's public IP address to reverse proxy server's private IP address.

Creating a virtual host entry for each website on the reverse proxy server

A virtual host entry is a set of configurations for the reverse proxy server to serve several name-based websites with a single IP address.

To serve multiple websites, we will create one set of virtual host entry for each of the domain name.

A sample virtual host entry on nginx looks like the following:

server {
    listen 80;
    server_name  cctv.adomainname.com;

    location / {
        proxy_pass http://192.168.0.107;
    }
}

The set of configurations tells the nginx server to delegate HTTP requests received at port 80 which are directed at the cctv.adomainname.com domain to the upstream server located at 192.168.0.107.

The nginx server will forward the HTTP responses that it receives from the upstream server located at 192.168.0.107 back to the senders who send the HTTP requests.

Typically, we keep each set of configurations for each domain in a separate configuration file inside the nginx configuration directory. On Raspbian, we can place the configurations files inside the /etc/nginx/sites-enabled directory.

Also, I would typically name the configuration file with the domain name and append .conf to the end of the filename. For instance, I will put the above sample configurations inside the /etc/nginx/sites-enabled/cctv.adomainname.com.conf file.

Configuring a domain name service to point all our domains to our router's public IP address

Once we had setup our reverse proxy server and configured our router to relay all the network traffic received on port 80 and port 443 to the reverse proxy server, the next task is to configure a domain name service to point all our domains to our router's public IP address.

If you happen to use DigitalOcean for you website, you can use DigitalOcean's domain name service to map all your domains for the websites to your router's public IP address. This is how you can create a sub domain and point it to an IP address in Digital Ocean control panel.

Using Let's Encrypt to generate SSL certificates for each domain on the reverse proxy server

Like other websites on the internet, we would want the websites that we host at home to be secured. Luckily for the world, Let's Encrypt was created to give everyone free SSL/TLS Certificates which are certified by a certificate authority that most browsers trust out of the box.

This is an example on how to use Let's Encrypt to generate an SSL certificate for a domain and configure an nginx server to serve HTTPS traffic based on the SSL certificate.

Advertisements

About Clivant

Clivant a.k.a Chai Heng enjoys composing software and building systems to serve people. He owns techcoil.com and hopes that whatever he had written and built so far had benefited people.

Udemy.com Homepage 300x250
Advertisements