Static site with IPFS

Started by diy05, Aug 14, 2022, 09:22 AM

Previous topic - Next topic

diy05Topic starter

TL;DR: IPFS permits you to host static sites distributed, which can be accessed through public caching gates (transparent reverse proxies) on the Internet, without the need to install a program for the visitor. Such websites can be distributed without a routable ("white") static IP address (it will work behind NAT), they remain operational in the absence of distributors for a short time (several hours), due to the cache on the gates.



You can optionally link your domain to the gates, and you can add DNS records to several gates at the same time to increase reliability and load balancing. The site can be downloaded by other IPFS clients and can help with distribution.
IPFS is great for static blogs, simple websites, file archives (as a replacement for Bittorrent), and just for transferring large files at once without first uploading them to any service.


What is IPFS?
IPFS is a decentralized peer-to-peer file transfer system, similar in principle to BitTorrent, but with the ability to access via HTTP, for the Web. All files downloaded by the user are temporarily cached by the IPFS daemon and distributed to other users who request them. Important files can be "pinned" to the IPFS daemon so they don't disappear from the cache.
Files added to IPFS receive global hash identifiers that do not change when the file is added again. Addressing in the network is carried out by content identifiers (CID), which contain a multihash. In the context of IPFS, they point to an unmodified or changing file, directory, metadata, or symlink.

Now, the project fully works only with static data, but there is already experimental support for the publisher-subscriber type protocol (publish/subscribe), as well as the implementation of IPFS in JavaScript, which works in the browser, which in the future will allow you to create dynamic sites (for instance, blogs with comments) with the possibility of real-time interaction (for example, chats).

One of the serious advantages of IPFS in comparison with other similar technologies is access to resources from the Internet through gates that are installed by companies and technology enthusiasts. They allow you to browse sites and download files without installing IPFS on your computer. The biggest gate is from Cloudflare, it also permits you to issue a free HTTPS certificate for a domain.


Why do you need IPFS, and where to use it?
The network permits efficient, distributed and decentralized distribution and downloading of data, including from a browser. I see the following real applications for the project:

    Free homeless hosting of static websites on a home computer, without a dedicated IP address (behind NAT), without a domain or with a domain;
    Uncensored hosting of high-risk sites that may be blocked by the government or third parties under the DMCA;
    Distribution of periodically changing or adding data that cannot be effectively distributed via Bittorrent (you will have to constantly re-create the torrent file and ask all distributors to download it again, which leads to seed fragmentation);
    An alternative to CDN that does not require settings on the side of the "CDN provider".


How to create a site in IPFS?
It's easier than with regular hosting! Consider homeless hosting a simple static site.

The easiest option is using the Siderus Orion graphical utility.
Install the utility, run it, click File → Add Directory, select the directory with the site files.

If everything was done correctly, the site will open through the siderus.com gate:
https://siderus.io/ipfs/QmU8rJjkXbfkPqEE3Dr8GiUMKF1vPnnNUKWdaB5DsZDfJ7/

That's it, your static site is available to other users as long as you keep the program running, or as long as it remains in the gate's cache.


How to bind an IPFS hash to a domain?
To make a website reachable at https://uncleoutrage.com/ rather than a long, ugly link, you need to add a few DNS records:

    A and AAAA records pointing to the gate's IP address, or a CNAME record pointing to the gate's domain name;
    TXT record "_dnslink", with content like "dnslink=/ipfs/HASH".


In my case, I added A and AAAA records pointing to cloudflare-ipfs.com IP addresses and "_dnslink.uncleoutrage.com" TXT record:

uncleoutrage.com. IN A 104.18.252.167
uncleoutrage.com. IN A 104.18.255.167
uncleoutrage.com. IN AAAA 2400:cb00:2048:1::6812:fda7
uncleoutrage.com. IN AAAA 2400:cb00:2048:1::6812:40a8
_dnslink.uncleoutrage.com. IN TXT "dnslink=/ipfs/QmU8rJjkXbfkPqEE3Dr8GiUMKF1vPnnNUKWdaB5DsZDfJ7"


You can get an HTTPS certificate for the linked domain from Cloudflare, you need to request it on a special page for obtaining a certificate.
If you do not need HTTPS support, you can add several A/AAAA records to different gates at once, the current list of working gates is available on the project forum.
If you update your site, you will need to update the TXT record for the domain as well.


How not to update the TXT record when the site is updated?
IPFS permits you to generate a special static hash identifier that points to a changing hash - IPNS. In the graphical client, just click File → Publish to IPNS, and specify your peer ID in the link or TXT record of the domain, and not the hash obtained when adding the directory. For instance:

https://cloudflare-ipfs.com/ipns/QmV97DGqaaTVn54RH9CLTi9hxXfr57gJQ4zGtyHcVbtfH6


nevertheless, the IPNS record needs to be updated (published) every few hours manually, and they resolve much slower than /ipfs/.

Apropos, IPNS can resolve not only CIDs, but also domain dnslink records — the site can be opened via a link like https://cloudflare-ipfs.com/ipns/uncleoutrage.com.
  •  

kpripper

Definitely a plus for the topic and for popularization. IPFS is a good idea, but they are sorely lacking in money and time, so development is moving at a snail's pace. The state of affairs today is two clients - Go and JS - that are eating memory and CPU like crazy, not very good at NAT and JS version has been making DHT for the second year. Everything is done in tiny steps when/if the developers have the time.

I would like to add an alternative idea for the development of that direction - in the wake of the recent pron ban on the toggle switch, moving everyone interested to distributed networks, for instance, one of the fediverse systems + hosting the actual pictures in ipfs.
In the presence of free hosting, as in the topic, this all becomes more or less uplifting.
  •  

Hemanth malli

The fundamental  advantage of IPFS is decentralized distribution
content so that content from the Internet can be accessed in circumstances of irregular access to the Internet and even take it
from offline cache.
"We create sites and web applications that do not have a central source server," Huang explained. "They can be distributed in the same way that the Bitcoin network is distributed." This something HTTP just can't be achieved, so IPFS will serve networks well,
not having first-class interconnections (for instance, in developing countries
or in the countryside).
  •