Logo

How I host this website on IPFS

Part 1 - The basics

December 06, 2018IPFS, IPNS

An email came in! Huzzah!!

Omar asks:

“Is mrh.io relying on IPFS? If the answer is yes, could you say how is it that fast?”

Omar and I had a nice exchange via e-mail and like a true friend he encouraged me to publish my process on the site. Here goes.

This will be a two-part series. Part 1 will cover the basics, and Part 2 will cover Private IPFS networks.

IPFS Website Hosting in General

So, the answer is yes! This site is hosted on IPFS. IPFS is great for hosting static content out of the box, and with tools like OrbitDB, you can work towards creating dynamic, decentralized apps hosted on IPFS.

This guide focuses on the former, and this is accomplished in a few major steps.

  1. Install IPFS and run it locally. I have a guide on IPFS and Docker here.
  2. Create your static content. More on this below
  3. ipfs add /path/to/content This should be wherever your index.html file lives.
  4. You will get a content hash, looking something like QmdGMhGo8qAv9uxhn2gWfMkM57ubfpM386wNz3GqPatT2H

It might take a second, but you should be able to more or less immediately view that content on any public gateway. Here are a few:

Using your own domain name with Your _dnslink DNS entry

We could stop here, but IPFS urls can be ugly. Eventually you’ll want to use your own domain name. This is accomplished via a technique called _dnslink, which require two custom DNS records:

  1. An A record, pointing to the domain name
  2. A ‘TXTrecord for_dnslink.yourdomain.comwhich contains the content id, like/ipfs/QmdGMhGo8qAv9uxhn2gWfMkM57ubfpM386wNz3GqPatT2H. Note the/ipfs/` prefix.

You can point the A record at https://ipfs.io, but you don’t control the garbage collection on that ndoe, so you can’t guarantee your content will last longer than 30 days.

IPNS publishing

When you update your content, you will need to change that TXT record every time, since each version of the content will have a different hash. You can avoid this by using IPNS.

I recommend creating a new key for each domain name you want to publish and using those:

$ ipfs key gen --type=rsa --size=4092 yourdomain.com
$ ipfs name publish --key=yourdomain.com QmdGMhGo8qAv9uxhn2gWfMkM57ubfpM386wNz3GqPatT2H

Then, your TXT record for \_dnslink.yourdomain.com might look like /ipns/QmdGMhGo8qAv9uxhn2gWfMkM57ubfpM386wNz3GqPatT2H (not a real IPNS name)

This tends to be slow - as you are publishing out a name and then resolving it via a consensus network of hundreds, maybe even in the thousands, of peers.

If this is all satisfactory, you can stop. But, if you want instant IPNS publication and resolution, and don’t mind a big trade-off, you can try using a private network. Post coming soon!

TallyLabLike reading about IPFS and want to see it in action? Check out my and @skybondsor's work on TallyLab
Mark Robert Henderson

This is the website of Mark Robert Henderson. He lives in Cape Ann and works for Haja Networks on the decentralized, distributed, and federated front.

Mark's social media presence is slowly and deliberately withering away, so the best way to reach him is via e-mail.