文档章节

基于IPFS建立网站

openthings
 openthings
发布于 2018/01/17 16:12
字数 659
阅读 792
收藏 0

基于IPFS建立网站

A short guide to hosting your site on ipfs

Adding your static website to ipfs is quite simple! Simply turn on your daemon:

$ ipfs daemon

And add the directory containing your website:

$ ls mysite
img index.html
$ ipfs add -r mysite
added QmcMN2wqoun88SVF5own7D5LUpnHwDA6ALZnVdFXhnYhAs mysite/img/spacecat.jpg
added QmS8tC5NJqajBB5qFhcA1auav14iHMnoMZJWfmr4k3EY6w mysite/img
added QmYh6HbZhHABQXrkQZ4aRRSoSa6bb9vaKoHeumWex6HRsT mysite/index.html
added QmYeAiiK1UfB8MGLRefok1N7vBTyX8hGPuMXZ4Xq1DPyt7 mysite/

The very last hash next to the folder name is the one you want, let's call it $SITE_HASH for now.

Now, you can test it out locally by opening http://localhost:8080/ipfs/$SITE_HASH in your web browser! Next, to view it coming from another ipfs node, you can try http://gateway.ipfs.io/ipfs/$SITE_HASH. Cool, right? But those hashes are rather ugly. Let's look at some ways to get rid of them.

First, you can do a simple DNS TXT record, containing dnslink=/ipfs/$SITE_HASH. Once that record propagates, you should be able to view your site at http://localhost:8080/ipns/your.domain. Now that's quite a bit cleaner. You can also try this on the gateway at http://gateway.ipfs.io/ipns/your.domain

Next, you might be asking "well what if i want to change my website, DNS is slow!" Well let me tell you about this little thing called Ipns (note the 'n'). Ipns is the Interplanetary Naming System, you might have noticed the above link has /ipns/ instead of /ipfs/. Ipns is used for mutable content in the ipfs network, it's relatively easy to use, and will allow you to change your website without updating the dns record every time! So how do you use it?

After adding your webpage, simply do:

$ ipfs name publish $SITE_HASH
Published to <your peer id>: /ipfs/$SITE_HASH

(Disclaimer: When using IPNS to update websites, it's important to think about that assets could be loaded from two different resolved hashes when updating your website, leading to outdated/missing assets unless accounted for)

Now, you can test that it worked by viewing: http://localhost:8080/ipns/<your peer id>. And also try the same link on the public gateway. Once you're convinced that works, let's again hide the hash. Change your DNS TXT record to dnslink=/ipns/<your peer id>, wait for that record to propagate, and then try accessing http://localhost:8080/ipns/your.domain.

At this point, you have a website on ipfs/ipns, and you may be wondering how you could expose it at http://your.domain, so that the Internet users of today may access it too without them having to know about any of this. It's actually surprisingly simple to do, all you need for this is your previously created TXT record and to point the A record of your.domain to the IP address of an ipfs daemon that listens on port 80 for HTTP requests (such as gateway.ipfs.io). The users' browsers will send your.domain in the Host header of the requests, and you have your dnslink TXT records, so the ipfs gateway will recognize your.domain as an IPNS name, and so it will serve from under /ipns/your.domain/ instead of /.

So, if you point your.domain's A record to the IP of gateway.ipfs.io, and then wait for the DNS to propagate, then anyone should be able to access your ipfs-hosted site without any extra configuration simply at http://your.domain.

Alternatively, it is possible to use CNAME records to point at the DNS records of the gateway. This way, IP addresses of the gateway are automatically updated. Note however that CNAME records to not allow for other records, such as a TXT to refer to the ipfs/ipns record. Because of this, ipfs allows to create a DNS TXT record for _dnslink.your.domain with dnslink=/ipns/<yourpeer id>.

So by creating a CNAME for your.domain to gateway.ipfs.io and adding a _dnslink.your.domain record with dnslink=/ipns/<your peer id> you can host your website without explicitly referring to IP addresses of the ipfs gateway.

本文转载自:https://ipfs.io/docs/examples/example-viewer/example#../websites/README.md

openthings

openthings

粉丝 331
博文 1159
码字总数 854419
作品 1
东城
架构师
私信 提问
【IPFS】(入门)基于IPFS和Ngrok构建自维护资源网关

一、应用背景 这篇文章通过一个简单的Demo,让大家可以搭建属于自己的协议网关,通过这种方式,我们跑在IPFS上的资源将不在受限,并且每个人都可以独立出自己的节点服务并分享给其他人、应用...

戴嘉乐Maple
2018/05/22
0
0
星际文件存储IPFS是如何颠覆云存储的?

一句话概括: IPFS(The InterPlanetary File System)星际文件存储系统是一种点到点的分布式文件系统,它连接的计算设备都拥有相同的文件管理模式。从某种意义上来说这个概念跟Web的最初理念...

马拉喀什
2018/05/02
0
0
IPFS星际文件系统之-- 环境配置

1. IPFS简介 是一个点对点的分布式超媒体分发协议,它整合了过去几年最好的分布式系统思路,为所有人提供全球统一的可寻址空间,包括、自证明文件系统、和,同时也被认为是最有可能取代的新一...

若与
2018/10/16
0
0
10月23日 IPFS原力区周二分享活动回顾

原力区阿信分享IPFS动态周报 web3峰会场地 柏林 Funkhaus 原力区孜然 技术周报解析 ipfs原创,作者:IPFSforce,转载请注明出处:http://ipfser.org/2018/10/24/1023-ipfs/...

IPFSforce
2018/10/24
0
0
分散型包管理器--Spore

Spore是一款基于ethereum和ipfs用于dApp开发的分散性包管理器。对于DApps的快速发展需要一个包管理。Spore是建立在truffle, ethereum和ipfs之上的这样一个包管理器的概念原型。 安装 请确保您...

匿名
2016/03/24
335
1

没有更多内容

加载失败,请刷新页面

加载更多

OSChina 周六乱弹 —— 不要在领导修风扇的时候打开电扇

Osc乱弹歌单(2019)请戳(这里) 【今日歌曲】 @巴拉迪维 :《Whats Up》 主唱妹子 Lina Perry 的嗓音实在太有力了,收放自如的自信才能唱出这么优秀的歌吧!#今日歌曲推荐# 《Whats Up》-...

小小编辑
今天
7
0
SpringBoot集成Elasticsearch并进行增删改查操作

一、创建工程 使用IntelliJ创建SpringBoot工程 SpringBoot版本为2.0.4 ElasticSearch为5.6.10 删掉蓝框中的文件(如上) 最后我们的目录结构(如下) 下面pom文件主要修改的是把spring boot从Int...

一字见心
今天
5
0
x001-版本介绍

python版本介绍 目前有2 和 3 有很多企业用的代码是2版本,随着技术的发展,以后用3的会成为大趋势 python3的安装 yum -y install wget gcc zlib-devel bzip2-devel openssl-devel ncurses-d...

侠客行之石头
今天
5
0
聊聊rocketmq的TransientStorePool

序 本文主要研究一下rocketmq的TransientStorePool TransientStorePool rocketmq-all-4.6.0-source-release/store/src/main/java/org/apache/rocketmq/store/TransientStorePool.java publi......

go4it
昨天
6
0
笔记

场外借贷, 质押 ,托管, 永续合约. 场外借贷,n签合同. 新功能 证券交易组负责中信证券机构及个人投资交易相关系统,服务机构及个人投资客户, 涉及到两融、期权、 期货、做市等境内境外创新业...

MtrS
昨天
6
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部