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:
- Demo of Site One and Site One Zip File (Ensure your zip file has no parent folder)
- Demo of Site Two and Site Two Zip File (Ensure your zip file has no parent folder)
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.
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:
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:
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:
- 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:
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
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
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
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:
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:
- Click on the Apps link of the of the Proxy Container
- Edit NGINX and choose the App TonicsCloud Nginx Recipe ยปยป [Reverse Proxy Simple] in the choose field
- Change the Server Name to:
[[DOMAIN_ONE]]
- Choose the Site One Container in the "Proxy To ๐" field
- SSL should be false for now
- 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 - Finally, you should have:
- Go-back to the Container Apps, please use the breadcrumb menu to make going back faster:
- Ensure there is no error message in the Nginx Msg box, if you see Reloaded, that is an indication that everything works fine
- 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]]
- Hit Save Changes
- Go-back to the Container Apps, wait for a Reloaded message in the ACME Msg and ensure there is no error in Msg
- 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:
At this point, if you visit your siteone and sitetwo domain, you should be greeted with Welcome to nginx!
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:
For Site Two: