In this article I will tell you how to start a static site in it that will be accessible both directly and by IPNS. The site will have a normal domain name due to the use of DNS. The domain name can be used to access the site directly, through a global and local gateway.
Conditions:
Let me remind you: InterPlanetary File System is a new decentralized file sharing network (HTTP-server, Content Delivery Network ). About her, I began the story in the article "Interplanetary File System IPFS" .
Domain name can contain only one dash in a row because of this line:
const DomainRegexpStr = "^([a-z0-9]+(-[a-z0-9]+)*\\.)+[az]{2,}$"
It checks the validity of the domain name. Domain restrictions will work until they accept the Pull request "Use more comprehensive hostname regex pattern Fix" .
The site directory must have a minimum set:
In the settings, change the line
"Gateway": "/ip6/127.0.0.1/tcp/8080", "Gateway": "/ip6/0.0.0.0/tcp/80",
Editing of settings is available in the web interface ipfs daemon
(it will be available after the client is ipfs daemon
command) or in the file ~/.ipfs/config
After editing the settings, the client must be restarted.
So we will open access to the gateway from the Internet.
We start the client.
>ipfs daemon
Take a look: Starting IPFS under Windows
We publish a directory with site content
ipfs add -r [ ] >ipfs add -r ..\ivan386.imtqy.com 18.17 KB / ? [-------------------------------------=------------------------------ added QmP2FJJXBjeVqm5DgJ4Q4ZjC5G9A3e74FRTFMV43kHP5p8 ivan386.imtqy.com/favicon.ico ... 80.25 KB / ? [-------------------------------------------------------------------- added QmXzx3rvzdRhLXPtzayG7abQzpyeH3JsyXWNt8CFqKy3Yv ivan386.imtqy.com/index.html ... added QmUsr9A8ggX79UKfQRTRCFX6FU9HrrWstHNyED5ygqgShA ivan386.imtqy.com
The last one will be the multi-cache root directory we need.
We bind the multihash directory to the ID
ipfs name publish [ ] >ipfs name publish QmNjE3iwCqY7729972CHRdFp3bGPosWoFHJ9YsTzea5icT Published to QmVBRmftY9ytHZ1z39b65gtEMY8Tq4Ri8AtmQeqULXPnm5: QmNjE3iwCqY7729972CHRdFp3bGPosWoFHJ9YsTzea5icT
Here in the answer is the first ID
Go to the DNS control panel add TXT record
@ TXT dnslink=/ipns/< id> @ TXT dnslink=/ipns/QmVBRmftY9ytHZ1z39b65gtEMY8Tq4Ri8AtmQeqULXPnm5
After some time (when the DNS update occurs), the content will be available at the website address and at the gateway at < >/ipns/< >
Publishing by ID should be used when the site is updated frequently. IPFS client through which content is published must be permanently on or off for short periods of time. For a day offline, my client forgot the id binding -> multi-cache. Apparently binding is stored only in DHT.
If these conditions are not suitable, you can use multihash .
So we published one site.
You can check the correct operation of the domain with the command:
ipfs name resolve -r < > >ipfs name resolve -r ipfs.io /ipfs/QmaYRrBpZQRjonxBpBBSLvYmy893ySPpXpHCakhomaQtkU
It happens that you need to publish several different sites.
For this:
We add to DNS TXT record of each dnslink directory.
@ TXT dnslink=/ipns/< id>/< > @ TXT dnslink=/ipns/QmVBRmftY9ytHZ1z39b65gtEMY8Tq4Ri8AtmQeqULXPnm5/magnet-converter
You can refer to another domain where dnslink is specified.
@ TXT dnslink=/ipns/< >[/< >] @ TXT dnslink=/ipns/ipfs.io
In dnslink, you can also specify a multi-tag on a directory or file.
@ TXT dnslink=/ipfs/<>[/< >]
to catalog
@ TXT dnslink=/ipfs/Qmce1EkrLpAV4gPxE75c68PhDWFCmEsedWkYVNNVU6Ut1S @ TXT dnslink=/ipfs/QmUsr9A8ggX79UKfQRTRCFX6FU9HrrWstHNyED5ygqgShA/magnet-converter
on file
@ TXT dnslink=/ipfs/QmXzx3rvzdRhLXPtzayG7abQzpyeH3JsyXWNt8CFqKy3Yv @ TXT dnslink=/ipfs/Qmce1EkrLpAV4gPxE75c68PhDWFCmEsedWkYVNNVU6Ut1S/index.html
These will be permanent links. This method is suitable for publishing rarely changing content. In this case, multi-content is immediately available and it will be immediately available if there is a copy of it in the IPFS network.
Accordingly, in this method of publishing when updating the contents of the site, you need to update the DNS record.
In order for users to automatically connect to the site through a local gateway, I suggest adding an A DNS record.
this-is-ipfs-site-use-local-gate A 127.0.0.1
This will allow the user to connect a simple proxy.pac which will load the site through the local gateway.
function FindProxyForURL(url, host) { if ( shExpMatch(url, "http:*") && dnsResolve("this-is-ipfs-site-use-local-gate."+host) == "127.0.0.1" ){ return "PROXY 127.0.0.1:8080; DIRECT" } return "DIRECT" }
Alternative: Switch your site to localhost (local IPFS gateway)
You can use IPFS hosting. To do this, add two entries to the DNS.
_dnslink TXT dnslink=/ipns/< id>/< > @ CNAME gateway.ipfs.io
But not all DNS hosting will allow you to specify the CNAME to the root domain.
In this case, our IPFS client can work with default settings. As soon as someone contacts our site, the IPFS client on the gateway.ipfs.io server will copy the contents of the site from us and transmit through the gateway. This option is useful if your server is behind NAT. But do not forget that the global gateway also has overloads.
So simply we make your site more accessible in a more modern way. Now it is available not only directly but also on the IPFS decentralized network.
Test site: ivan386.tk
Through the global gateway: ipfs.io/ipns/ivan386.tk
Through the local gateway: 127.0.0.1:8080/ipns/ivan386.tk
Made your client release with fixes :
We host a site in the interplanetary IPFS file system under Windows
Source: https://habr.com/ru/post/316468/
All Articles