facebook youtube pinterest twitter reddit whatsapp instagram

Hosting Multiple Websites on a Server with TonicsCloud

In the previous guide, I covered Hosting a Static Site in TonicsCloud, that setup is limited in the sense that you can't host more than a site in a server.

In this guide, we would take it a step further, I will provide you with a step-by-step instructions on setting up multiple websites on a server with TonicsCloud.

There is no limitation on the number of websites (Containers) you can have in a server, the limitation is the resources, so, go for an higher plan if you are planning to host too many websites in a Server.

I have prepared the following materials:

The Zip files would be useful along the line.

Strategy

  • Deploy a Server
  • We do the DNS setup, you should ensure the domain name point to the IP address of the instance/server
  • In the server, you need...
  • At least 3 containers
  • The first container would be for "Site One", the second container would be for "Site Two" and the third container is for the "Reverse Proxy", the Reverse Proxy container would be the one that directs incoming web requests to the appropriate website containers based on the requested domain.

Now, let's follow the steps in our strategy, first, we...

Deploy an Instance

To Add a new Instance, go-to: Cloud โ†’ Instances โ†’ Add New

You would see the instance form, choose the instance name, the region you want the instance to be deployed to and the plan you want.

Deploying Instance

Hit Deploy Instance to deploy it, then wait for a while for the instance to be configured, might take between 1 minute to 5 minutes, chill out and take some ๐Ÿต

Once the instance is deployed, you would get Running in the status, if you are not getting any info, please hit the reload after a minutes or so:

Deployed Instance in Running State

Once the instance is in the running state, you can either start to Add Container, please click the Edit button to get the IP info if you are managing the domain records outside of TonicsCloud:

Edit Instance Page

Configuring Domain Records

Skip this section if you are not managing the Domain Records in TonicsCloud, otherwise, let's bind the domain to the newly created instance.

Do the below step for both site one and site two

  • First, add a new domain if you already haven't added one, by going to: Cloud -> Domains -> New Domain
  • Enter your domain name, and choose the instance you just deployed in "Default A/AAAA Value From ๐Ÿ‘‡", then hit Save Changes, you do not need to do anything else, it would automatically fill the IP addresses for you.
  • Once you hit Save Changes, it would redirect you to the Domain List page, ensure the info does not have no error, depending on which record you are creating, the below is an example of success:

    Domain Records created
  • If you click on the domain Edit link, you would see further instructions on how to configure the nameserver at your domain registrar

Adding Containers

Once your domain is binded or is pointing to the instance IP, you can create a container, click on the Cloud menu:

Deployed Instance in Running State

and click Add Container.

For Container One (Site One Container):

  • Add Container Name, in my case I would enter: "Site One Container"
  • Add Container Description: "This is site one container"
  • In the Container Settings, click on the Variable Recipe tab, delete everything and use this (please change siteone.com to your site name):
    ACME_DOMAIN=siteone.com
  • For Image, choose Nginx, if you do not pick a version for the image, it would use the first option
  • For Instance, select the instance you want to place the container onto
  • Finally, hit the Deploy Container button and that would be provisioned in less than a minute, hit reload button to track the changes

Adding Site One Container

For Container Two (Site Two Container):

  • Follow the above steps for container one but in the Variable Recipe, change it to the second site name:
    ACME_DOMAIN=sitetwo.com
  • Choose NGINX image, select the instance you want to deploy it to, and Deploy Container

Adding Site Two Container

For Container Three (The Proxy Container):

  • This is same as the above steps except in the Profiles Tab of the Container Settings, select Proxy Protocol 80 - HTTP & Proxy Protocol 443 - HTTPS
  • In the Variable Recipe Tab of the Container Settings, use the below:
    ACME_EMAIL=yourmail@domain.com
    DOMAIN_ONE=siteone.com
    DOMAIN_TWO=sitetwo.com
  • Choose NGINX image, select the instance you want to deploy it to, and Deploy Container

Adding Proxy Container - Step One

Adding Proxy Container - Step 2

If everything goes fine, the 3 containers should be in the running state, hit reload button to update the status if it isn't in the running state:

All containers in running state

Configuring The Containers

Once the container is deployed, the only thing left is configuring Apps in the container, for example, uploading your static project, HTTPS, and the likes.

Starting with...

Proxy Container:

  1. Click on the Apps link of the of the Proxy Container
  2. Edit NGINX and choose the App TonicsCloud Nginx Recipe ยปยป [Reverse Proxy Simple] in the choose field
  3. Change the Server Name to: [[DOMAIN_ONE]]
  4. Choose the Site One Container in the "Proxy To ๐Ÿ‘‡" field
  5. SSL should be false for now
  6. Hit the Repeat Server Block and repeat step 2 - 5, but change the Server Name to: [[DOMAIN_ONE]] and choose Site Two Container in the "Proxy To ๐Ÿ‘‡" field
  7. Finally, you should have:
    Proxy Container Nginx EDIT
  8. Go-back to the Container Apps, please use the breadcrumb menu to make going back faster:
     Proxy Container Nginx Edit Breadcrumb
  9. Ensure there is no error message in the Nginx Msg box, if you see Reloaded, that is an indication that everything works fine
  10. If you want free https, Edit ACME, hit Add New Site, in the firs site, enter [[DOMAIN_ONE]] and in the second one, enter [[DOMAIN_TWO]]
    Proxy Container ACME Edit
  11. Hit Save Changes
  12. Go-back to the Container Apps, wait for a Reloaded message in the ACME Msg and ensure there is no error in Msg
  13. Finally, Edit Nginx one more time, set each of the SSL option to TRUE and save changes.

If everything went well, Acme and Nginx should all have Reloaded:

Proxy Container ACME AND NGINX Reloaded

At this point, if you visit your siteone and sitetwo domain, you should be greeted with Welcome to nginx!

Welcome To NGINX message

I am sorry if you are tired at this point ๐Ÿ˜•, but the only thing left is adding the archive and just using some default settings:

For Site One and Site Two Containers:

  • Click on the Container Apps
  • Edit Unzip
  • Copy and Paste the zip link in the Archive File, then hit Save Changes
  • Go-back to the Container Apps
  • Ensure there is no error message in the Unzip Msg box, if you see Reloaded, that is an indication that everything works fine
  • Edit Nginx
  • In the Choose Field, please select: App TonicsCloud Nginx Recipe ยปยป [Static Site (HTTP)], then scroll to the bottom and hit Save Changes
  • and you are done ๐Ÿ˜Š

Result

For Site Two:

Site One Preview

For Site Two:

Site Two Preview