Hosting a Website on IPFS
Sep 15, 2015 · 2 minute read ·
0 Comments
IPFSIPNStutorialfor-future-me
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
Step 2. Create a simple static site
|
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<title>Hello IPFS!</title> |
|
<link rel="stylesheet" href="./style.css" /> |
|
</head> |
|
<body> |
|
<h1>Hello IPFS!</h1> |
|
</body> |
|
</html> |
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
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 ipns
not ipfs).
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 peedID gets the hash of your latest site.