Hosting Web site on IPFS

IPFS is one of popular topics for We decided to go forward and publish our site on IPFS. Lets take a closer look on how is publishing to IPFS done.

Advantages of IPFS

IPFS is global distributed filesystem. Its main function is to store and distribute static content. Content can be replicated, deduplicated and is identified by secure hash. IPFS can be used for hosting static web sites.

Dynamic sites needs to include fragments from servers outside IPFS. There are some experiments with using PubSub to communicate with other IPFS nodes and deliver dynamic content but they are not yet stable for production use.

IPFS Node installation

While there are several choices how to install IPFS we would stick with go-ipfs. Installation is quite simple, you need just to unpack it and then run ipfs init followed by ipfs daemon . After this you should have IPFS node running.

Generate static website

This depends on your website software used. Netmag uses Hugo. In our case all we need is to adjust configuration in config.toml to make links relative.

relativeURLs  = true
uglyURLs      = true
canonifyURLs  = false

If links are still not relative it is because they are declared as absolute in theme. In that case add –baseURL command line argument. After updating configuration run hugo and website will be generated into public directory.

Add generated site to IPFS

ipfs add --pin=false --recursive --quiet public

This will output something like:


Last hash printed is root of our site. We have to remember it for next step.

Last step is to publish DNSLink. This will allow web browser with IPFS Companion extension installed to load our site from IPFS and not using standard HTTP protocol. We need to add TXT DNS record: IN TXT "dnslink=/ipfs/QmSoZRxirKX7tFjAA55EkNS7GiNo1VmJeB8T8dhnnwRKEh"

Pin to mirror node

We may choose to mirror published website to another IPFS node which is under our control. This will increase availability and load speed. This is useful if our primary IPFS node is notebook which is not running 24/7.

ipfs pin add QmSoZRxirKX7tFjAA55EkNS7GiNo1VmJeB8T8dhnnwRKEh

After it is done we can verify that entire tree structure is stored correctly and list pinned entries.

ipfs pin verify
ipfs pin ls --type=recursive

Pin to pinning service

Using pinning service is alternative to pinning into our another node. To pin our website to one of public IPFS pinning services log in and navigate to PIN Hash or similar function then enter hash for root folder of our site - QmSoZRxirKX7tFjAA55EkNS7GiNo1VmJeB8T8dhnnwRKEh.