Hosting a Website on IPFSSep 15, 2015 · 2 minute read · Comments
This is a quick tutorial that will teach you how to host a simple static website on IPFS, and use IPNS to keep a single id when you change the sites content
Step 1. Install IPFS
Install IPFS as described at https://ipfs.io/docs/install/
Step 2. Create a simple static site
Step 3. Add to IPFS
Next you need to add the site to IPFS.
$ ipfs add -r site/
You should see something like this
added QmTVJ4XtUhqb6KMW8kxDwArVweACcy7VXAfinEks9Fd8cJ site/index.html added QmZL2UBTwnhcLv66fARL9UV8W8a9ZA4iwTLcaUCsB1u1yW site/style.css added QmeYxwj4CwCeGVhwi3xLrmBZUUFQdftshSiGLrTdTnWEVV site
The hash on the last line is the root of your site, you can visit is by opening
https://gateway.ipfs.io/ipfs/<your hash here>. So the example site is at
Step 4. Publish to IPNS
Now you have a simple static site hosted on IPFS. The problem is, whenever you update your site, the hash will change, and any links you have shared will continue pointing to the old version. You need a way to always share the latest hash. That’s where IPNS comes in. It allows you to store a reference to an IPFS hash under the namespace of your peerID (hash of your public key).
$ ipfs name publish <your site hash>
That will return your peerID and the hash you are publishing to it. You can confirm by running
$ ipfs name resolve <peerId>
or by viewing
https://gateway.ipfs.io/ipns/<peerID> (notice the directory is
Step 5. Done
That’s it. You’re done. Whenever you update your site, just do step 4 again, and IPNS will make sure anyone asking for your peerID gets the hash of your latest site.