IPFS for Beginners – Host Your Static Website
Posted on LearnThings.Online on May 20, 2020
In this tutorial, you’ll learn how to host your static website on IPFS. You can read “IPFS for Beginners – Storing Data in a Distributed Hash Table”. You may also skip the previous tutorial if you don’t have coding experience.
Review from “IPFS for Beginners – Storing Data in a Distributed Hash Table”
In the previous tutorial, you already learn how to download your website and put it on the IPFS network. Also, you have learned how to visit your website. However, you may face 3 problems if you follow the steps.
- If you close your local node, no one have responsible to keep your files. You may find your file disappear after 1 day.
- Your IPFS link may change if you update your website since the hash value changed. You can solve the problem by generating an IPNS link. However, you may like to use your own domain name for SEO or marketing.
You will learn how to solve these 2 problems in this tutorial.
Pin your website to other nodes
In the pervious tutorial, you can pin your IPFS on your client by the command.
ipfs pin add <your_ipfs_hash>
However, if there are no other nodes download your website, the IPFS network will clear the website when your IPFS daemon shutdown. To keep your website on IPFS, you can open a server to keep the daemon or pin your website to more nodes using an IPFS cluster.
Also, there are also IPFS pinning services like Pinata, Eternum, and Temporal … etc. We will use Pinata here.
You can directly upload your files or directory on the Pinta dashboard.
Pinata
Also, you can directly pin by your IPFS hash.
Pin By Hash on Pinata
You can find the file you pinned on the pin explorer.
Now, you can keep your file on IPFS network.
https://gateway.pinata.cloud/ipfs/QmXxK4EupcdNtRbAgNbgDtb9B7CMBXBG3tmPDkXUk4iy5F
In addition, team behind IPFS, the Protocol Labs has develop a blockchain project called Filecoin as an incentive layer for IPFS. The Filecoin plan to launch their main-net on July 2020. Once it launched, you may also pin your files by paying its native cryptocurrency Filecoin.
Use your own domain name
DNSLink provides a simple protocol to link content and services directly from DNS.
Picture from DNSLink.io
According to DNSLink.io You can store a link using any DNS domain name by putting the link in a TXT record at a specific subdomain. Then, you can resolve the link from any program by looking up the TXT record value.
You need to register your domain name A and AAAA records point to an IPFS gateway. Then, register a TXT record with DNSLink record value.
Using ipfs.io gateway as an example.
A records to “209.94.90.1”
AAAA records to “2602:fea2:2::1”
TXT records with “dnslink=/ipfs/<your_ipfs_hash>”
Register records for your domain
We use sub-domain ipfs.learnthings.online here. You can check our website by http://ipfs.learnthings.online link. The URL will direct to the file on https://ipfs.io/ipfs/QmXxK4EupcdNtRbAgNbgDtb9B7CMBXBG3tmPDkXUk4iy5F
You can update <your_ipfs_hash> if you update your website.
If you want to get SSL certification for your website, the CloudFlare incorporates with IPFS provide a gateway service. You can register a CNAME records point to cloudflare-ipfs and TXT records with DNSLink record value.
CNAME records to “cloudflare-ipfs.com”
TXT record for “_dnslink.<your domain name>” and value “dnslink=/ipfs/<your_ipfs_hash>”
Register your website on Cloudflare if you don’t use Cloudflare DNS service.
cloudflare-ipfs service
Be careful, the TXT register on subdomain name “_dnslink.<your_domain _name>” rather than “your_domain_name” directly.
In this case, we use dht.learnthings.online. You can visit the website with https https://dht.learnthings.online.
Read More
IPFS for Beginners – Storing Data in a Distributed Hash Table.
Book about DApps for beginners.