基于IPFS建立网站

news/2024/5/20 2:32:24/文章来源:https://blog.csdn.net/weixin_33922672/article/details/92210095

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

基于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://my.oschina.net/u/2306127/blog/1608592

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_718668.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

微信7.0.9内测版来了,更新了这几项,网站上新一款影视软件

微信7.0.9安卓微信7.0.8正式版才不足一个月这就来了7.0.9的测试版本&#xff0c;微信这更新速度确实不慢&#xff0c;本次又更新了那些呢&#xff1f;今天我给大家说说吧&#xff01;咱们先从加好友这里说起把&#xff0c;添加好友的时候界面变化&#xff0c;增加了直接备注昵称…

7个顶级资源搜索网站,不知道太可惜了!

说起搜索资源&#xff0c;大家肯定先想到百度&#xff0c;的确“度娘”很万能&#xff0c;能帮我们解决很多问题&#xff0c;但毕竟百度资源有限&#xff0c;用的人多了就造成重复的问题&#xff0c;接下来&#xff0c;小编给大家分享7个顶级资源搜索网站&#xff0c;能满足你很…

黑科技之资源搜索网站

欢迎加入BIM行业开发交流1群 群号:711844216 一、背景 大家经常会有搜索视频&#xff0c;音乐&#xff0c;PDF&#xff0c;APP等资源的需求&#xff0c;然而通过现有搜索引擎不是很方便找到自己想要的东西&#xff0c;这里笔者推荐几个不错的免费网站&#xff0c;基本上用起来…

6个不为人知的黑科技资源网站,绝对让你大开眼见!

在线资源网站&#xff0c;几乎我们每个人都需要的&#xff0c;不仅可以帮助我们下载视频、音乐、还可以帮组我们找资源模板以及各类学习资料等等&#xff0c;是不是非常神奇呀&#xff01;&#xff0c;那请不要眨眼&#xff0c;下面为大家连续分享6个不为人知的黑科技资源网站&…

PPT总是做不好?那是因为你没有收藏这7个在线网站,建议私藏一份

PPT不管你是在工作上还是在学习上都需要用的上&#xff0c;它与我们是密不可分的&#xff0c;比如你在公司工作汇报时候&#xff0c;还是在学校里面完成老师布置的作业都需要&#xff0c;它可以帮助我们完成各种演讲制作、完成作业&#xff01; 但制作PPT时候经常会需要许多素…

6个帮助自我提升的自学网站,让你从此人生开挂!

其实很多人在从学校毕业之后还是想多学点东西充实自己的&#xff0c;但要么就是找不到好平台、好方法&#xff0c;要么就是没有时间。 这些问题&#xff0c;小编说不定可以帮大家解决哦。 今日分享&#xff1a;6个帮助自我提升的自学网站&#xff0c;让你从此人生开挂&#x…

珍藏7个不可多得的自学网站,送给正要提升自己的人,一生受益!

你还在每天庸庸碌碌的过日子吗&#xff1f;你不想改变下自己吗&#xff1f;曾近有句话说过&#xff1a;"知识很宝贵&#xff0c;就好像是金矿。学好知识&#xff0c;掌握好本领&#xff0c;会对我终身有益"。 其实网上有很多一系列的教学视频网站&#xff0c;我们只…

好嗨哟,这5个超牛的资源网站,让你轻松无忧找资源!

马上过年啦&#xff01;兴奋、激动、睡不着&#xff1f;这个时候来点什么好呢&#xff1f;看个电影&#xff0c;找不到资源&#xff1b;听个音乐&#xff0c;没有会员&#xff1b;看个电子书&#xff0c;没有权限&#xff1f;这些让人头疼的问题&#xff0c;小编今天为大家“出…

一个网管8年来运营网站的辛酸经历

一直以来&#xff0c;都想写点什么&#xff0c;但思绪有点混乱&#xff0c;不知从何下笔。这要源于2015年进入股市惨败直至17年投资生意失败&#xff0c;三年时间耗费了所有积蓄&#xff0c;还倒欠了一些外债&#xff0c;所以无心打理其他事情&#xff0c;今天整理了一下心情&a…

找优秀项目很好的网站推荐

一、背景 今天在找资料的过程中发现一个很好的网站&#xff0c;可以快速找到关键词下优秀的项目 二、网址 https://awesomeopensource.com/ 比如我们在里面搜索BIM&#xff0c;可以发现16个开源的资源 三、注意事项 1.大家好&#xff0c;我是黑夜の骑士&#xff0c;欢迎大…

网站用户的漏斗转化率概念

Funnel &#xff08;或称 Conversion Funnel&#xff09; 是网络业最基本的概念之一&#xff0c;它的意思是 100 个人路过你的网站&#xff0c;你能够把几个人变成忠实顾客。 一般最基本的电子商务 Funnel&#xff0c;大概分五个步骤&#xff1a; 100% — 流量20% — Email 订户…

wordpress yoast调用自定义类型_WordPress的SEO清单:20个提高网站的排名的技巧

【长文预警】本文约7000字&#xff0c;阅读时间15分钟。你说服自己选择WordPress作为网站CMS的原因之一可能是你已经了解这一平台的SEO友好性。其实&#xff0c;只需要在Wordpress主页看一下他们所宣传的功能列表&#xff0c;就会发现 SEO友好性是其中一个亮点功能。当然&#…

地址总线是单向还是双向_单向链接是什么?对SEO优化有影响吗?

什么叫单向连接&#xff1f; 说白了的单向连接是让别人连接到您的网址&#xff0c;但您不容易将其连接回来。 它与互相的友情联系在一起。&#xff0c;它一般是SEO最新项目绩效考核的重要指标值&#xff0c;在操作流程中&#xff0c;大家十分清楚&#xff0c;它对seo提升具有积…

seo日常工作表_做好SEO必须要会的4个数据分析表

很多SEO半路出家&#xff0c;然后学完了以后&#xff0c;去公司上班&#xff0c;上级领导或者老板要他做一个SEO数据报 表都不会。起码一大半做SEO的都是直接查询下排名&#xff0c;汇报工作&#xff0c;然后结束。实际上这种SEO行为是很难给老板一个满意的答复&#xff0c;其次…

网站手工添加一行数据_本地免费搭建婚恋社交交友网站教程

有许多的朋友们想要搭建属于自己的婚恋社交交友网站&#xff0c;但是自身没学过代码&#xff0c;不懂技术&#xff0c;或者是学生或者个人&#xff0c;并没有太多的资金或者不太想投入太多的资金&#xff0c;所以就只能是想想而已&#xff0c;今天要与大家讲的是免费搭建婚恋交…

5分钟自动更新php,使用织梦计划任务功能让网站每5分钟更新一次

使用过dedecms织梦系统的人都知道有一个计划任务的功能&#xff0c;这个功能很多人不知道怎么使用&#xff0c;今日小编就讲讲如何使用计划任务让网站每5分钟自动更新首页&#xff0c;也就是自动生成内容来自dedecmsindex.html文件&#xff0c;让网站的静态文件保持一个更新的状…

seo上排名小技巧,你知道几个?

现在在做网站优化的时候&#xff0c;很多人都做一些不那么相关的工作&#xff0c;假如是一个专业的SEO人员在网站优化中都会专注于基础优化。  而百度对网站的要求是部分SEO优化的基础&#xff0c;是另外彻底依赖于用户点击&#xff0c;假如网站排名的开端都不是很好&#xf…

TLS 1.2 协议现漏洞,多个网站受影响

百度智能云 云生态狂欢季 热门云产品1折起>>> TLS 1.2 协议被发现存在漏洞&#xff0c;该漏洞允许攻击者滥用 Citrix 的交付控制器&#xff08;ADC&#xff09;网络设备来解密 TLS 流量。“TLS 1.2 存在漏洞的原因&#xff0c;主要是由于其继续支持一种过时已久的加…

网站打不开怎么检查服务器,网站打不开?利用排除法,简单判断问题出在哪里。...

1、查看域名解析是否正常(重点)Windows操作系统用户请点击 开始->运行->输入"cmd"回车进行DOS命令窗口->输入ping 你的域名(如:ping www.163.com)->回车(1)输出结果显示的IP与空间后台分配的IP一致表示解析正常&#xff0c;如果IP不对或没显示IP就证明域…

项目实战2—实现基于LVS负载均衡集群的电商网站架构

负载均衡集群企业级应用实战-LVS 转自https://www.cnblogs.com/along21/ 实现基于LVS负载均衡集群的电商网站架构 背景&#xff1a;随着业务的发展&#xff0c;网站的访问量越来越大&#xff0c;网站访问量已经从原来的1000QPS&#xff0c;变为3000QPS&#xff0c;网站已经不堪…