This guide will help you associate your domain or subdomain to your SPKCC node. This guide can also be used for the DLUX node or ragnarok node as well. In this guide, I will be using CADDY as my web server. There are so many advantages in using CADDY over other web servers. I see two primary advantages and that's why I use CADDY for all my web server needs.
- Easy to use. Very simple setup commands
- Caddy takes care of SSL certificates by itself. We don't have to manually set up an SSL certificate.
The second point is the main reason why I wanted to explore CADDY. Now let's get into setting up a domain or subdomain for our SPKCC node.
Step 1: Install Caddy on the server
The steps are very simple to install Caddy on the server. If you are using an NGINX instance already, you can stop it and then install Caddy. If you are starting fresh, you can straight away go and install Caddy. Below are the commands to get started. All my servers are Ubuntu 20.4 and this worked well for me and I'm sure this should work on other versions of Linux as well.
curl -fsSL https://apt.privex.io/add-repo.sh | bash
apt update
apt install -y caddy
I'm using a Virtual machine box from @privex so I used their repo to get the package. You can also use a different package link to the repo. The steps were very simple.
Step 2: Edit the Caddyfile
Caddyfile is the configuration file that has all the information about the sites we are hosting. It is one place where we do all the configurations required for the domain association. The below command can be used to access the Cadyfile
sudo nano /etc/caddy/Caddyfile
The default caddy file contents looks like the below:
Once the file is opened, you can make changes in such a way that domain\subdomain is set. I commented out all the existing lines in the file and just added the reverse_proxy line alone. You can also remove all the existing contents of the file and just have the active content alone. That also works. My final Caddyfile looked similar to the below.
The RPC node of SPK usually runs at 3001. But it can be changed to any port in the .env file. In my case, I'm running it on a 3002 port. The application is already running using Pm2. When I set a reverse_proxy in the caddy file. All the requests that are reaching to spkccc.hivedata.live will be routed to the localchost:3002 port internally. We can have multiple such configurations running in the same machine. We can run a dlux node, ragnarok node, and spkcc node in the same machine.
In my example, I have added a subdomain called herpc. You can also directly associate a domain as well. You can save and exit the file now.
Step 3: Enable your Caddy service
You can either go to the directory of the Caddyfile and run the service manually with the below command.
caddy run
Or enable it as a service. In my case, I enabled it as a service with the below commands.
systemctl enable caddy
systemctl status caddy
systemctl restart caddy
The status check command will tell you if the service is running fine or not. In some cases if the configuration is incorrect or if there are unwanted characters in the Caddyfile, the service may fail to run. The status command will show you an active (running) status similar to the below.
Sometimes the caddy service would be already running on your machine and you may not need to start it again. Only if you are making changes to the Caddy file, do we have to restart the service for the changes to take effect. Otherwise, we are good.
Step 4: Point your domain to the IP address of the server
This is the last step to completing your setup. We have to point the domain\subdomain to the IP address of the server so that all the requests coming to the domain are redirected to the server and caddy is able to serve those requests.
In my case, I have my domains on Namecheap and as I was adding a subdomain, it was very simple to just add an A record in the domain's DNS configuration and point it to the IP address of my witness server.
The configuration page looks similar to the above and it will vary from one service provider to another. In the Value field, you will have to enter the IP address of your spkcc node.
You can do this step before all the other steps as well. It doesn't really matter if you add the A record before or after. It is good to do it before because it usually takes some time for the domain to propagate. If you do this step first, the propagation would have happened before you complete the other steps.
Step 5: Test if our configuration worked
It is quite simple to test if the configuration worked or not. Try visiting your node URL directly from a browser. In my case, it is https://spkcc.hivedata.live/
. The URL worked. It should give you a result similar to the below.
You can also test this on your Linux machine using the CURL command. The output should look like the below.
With this, we are done with associating a subdomain to the SPKCC node. The good thing about Caddy is, that we don't have to deal with SSL certificates. Caddy takes care of it.
If you like what I'm doing on Hive, you can vote me as a witness with the links below.
|
|
|
|
|
|
Posted with STEMGeeks