Serverless static site using IPFS

    TL; DR : IPFS allows you to host static sites on a distributed basis, which can be accessed through public caching gates (transparent reverse proxies) on the Internet without having to install a program for a visitor. Such sites can be distributed without a routable (“white”) static IP address (will work for NAT), they remain operational with a short-term (several hours) absence of distributors, due to the cache on the gates. You can optionally bind your domain to gates, and you can add DNS records to several gates at the same time, to increase reliability and load balancing. The site can download other IPFS users and help with distribution.
    IPFS is great for static blogs, simple websites, file archives (as a Bittorrent replacement), and also just for the one-time transfer of large files 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 access via HTTP, for the Web. All files downloaded by the user are temporarily cached by the IPFS daemon and distributed to other users requesting them. Important files can be “attached” (pin) to the IPFS daemon, then they will not disappear from the cache.
    Files added to IPFS receive global hash identifiers that do not change when the file is added again. Network addressing is performed by content identifiers (CID) , within which the multi-cache is contained . In the context of IPFS, they indicate a non-changing or changing file, directory, metadata, or symlink.

    At the moment of development, the project fully works only with static data, but there is already experimental support for the publisher-subscriber protocol (publish / subscribe), as well as the Javascript implementation of IPFS running in a browser, which in the future will allow creating dynamic sites (for example, blogs with comments) with the ability to interact in real time (for example, chats).

    One of the major 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 allows you to issue a free HTTPS certificate for a domain.

    Why do I need IPFS, and where to use it?

    The network allows to distribute and download data efficiently, distributedly and decently, including from the browser. I see the following real project uses:

    1. Free homeless hosting of static websites on a home computer, without a dedicated IP address (behind NAT), without a domain or with a domain;
    2. Non-censored hosting of high-risk sites that may be blocked by the state or by third-party companies within the DMCA;
    3. Distribution of periodically changing or adding data that cannot be efficiently distributed through Bittorrent (you will have to constantly re-create a torrent file and ask all distributors to download it again, which leads to fragmentation of the seed);
    4. An alternative to a CDN that does not require settings on the “CDN provider” side.

    How to create a site in IPFS?

    It is easier than with regular hosting! Consider homeless hosting a simple static site.

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

    After some time, a window will appear with the information of the imported content:
    image

    Go to the “Files” tab, right-click on the hash → Open in browser:
    image

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

    That's all, your static site is available to other users while you are running the program, or while it remains in the cache of the gate.

    Alternative console version - download the official go-ipfs client , unpack, initialize and run as written on the site :
    ipfs init
    ipfs daemon

    Next, add our directory with the site files:
    ipfs add -r ./www.uncleoutrage.com
    …
    added QmXdaairbPoSGV98sQ3GsEuevVTE1EBUzZ4PhbLfKVh1nX www.uncleoutrage.com/images/fanart
    added QmdFbHdzzB4qBBkn8UsyHnjg1BKEtm9d5LaTyv5aZd8bbE www.uncleoutrage.com/images/gigs/thumbs
    added QmVPJ3Mr8gZL5x15A9XARC1uHASqb2JMsKTT7mWs37UmBo www.uncleoutrage.com/images/gigs
    added Qmd3AbVwMVE9W6ZSEuax96Xnymbnic4XVCdNEKBPZcWi5c www.uncleoutrage.com/images/live/thumbs
    added QmebUfmT2wmZMbJcAmSMS4cZJr4guTqV67xNJ3hiQGsLYx www.uncleoutrage.com/images/live
    added QmaEVaRiUUXfDnjjuXHGGsg7jDaFrCaxS7wi6q83q4N1uu www.uncleoutrage.com/images/misc/thumbs
    added QmW2ZivQF5eh5LHSLet298AhKCHiQsFV6rvUFvMcCkLopo www.uncleoutrage.com/images/misc
    added QmZXXn7abBvj7SvYJoYMAXUeajP6A1UABKENrNwuhKqofk www.uncleoutrage.com/images/promo/thumbs
    added Qmcx6bMKur4Anzh91bJC6o5vMPftzocSMmd7iYxoGwQrNX www.uncleoutrage.com/images/promo
    added QmW8P3ZnvKUytCWJF6y6wvBD8XAkk4bvJoVK8j3apokzLS www.uncleoutrage.com/images
    added QmXG1QjfpCjErQBGZvF6VWBryXe9WFLPqhrsGWtikACVwR www.uncleoutrage.com/js
    added QmYGXwLJBnqXwWYGKVtjZtmwncgwNoqNmnYqo1NTinTGBp www.uncleoutrage.com/theband/misc/pages
    added QmWg4JyZ4ox9hcHt6JGBfzUm5CqWsb6DixUksamFvbirH4 www.uncleoutrage.com/theband/misc
    added QmPtn9XBhWqe7A1z3ikktWExSPSM27LTzUL3US9N5xcAPB www.uncleoutrage.com/theband/redsaug21/pages
    added QmaGV6kfLdL1bKGBBHYJLDVstiejAANayBZt16NMF9g9j9 www.uncleoutrage.com/theband/redsaug21
    added QmScmcUAdC5pinMxaoLuXSy3FDUAX5E68dADnGjYZbPUiY www.uncleoutrage.com/theband
    added QmU8rJjkXbfkPqEE3Dr8GiUMKF1vPnnNUKWdaB5DsZDfJ7 www.uncleoutrage.com

    The last hash is the directory hash, and we need it.

    We make a link to open the directory via the gate manually, like:
    https://домен/ipfs/хеш

    For example:
    https://cloudflare-ipfs.com/ipfs/QmU8rJjkXbfkPqEE3Dr8GiUMKF1vPnnNUKWdaB5DsZDfJ7

    How to bind an IPFS hash to a domain?

    To make a website accessible by the domain https://uncleoutrage.com/ , and not by a long and ugly link, you need to add several DNS records:

    1. A and AAAA records pointing to the gateway IP address, or CNAME record pointing to the gateway's domain name;
    2. TXT-record "_dnslink", with the contents of the form "dnslink = / ipfs / HASH".

    In my case, I added A and AAAA records pointing to the IP addresses of cloudflare-ipfs.com, and the TXT record "_dnslink.uncleoutrage.com":
    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 an associated domain from Cloudflare, you need to request it on a special certificate receipt page .
    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 .
    In the case of updating the site, you will have to update the TXT-domain record.

    How not to update the TXT-record when updating the site?

    IPFS allows to generate special static hash identifier indicating the changing hash - IP N S . In the graphical client, it is enough to click File → Publish to IPNS, and indicate in the link or in the TXT records of the domain your peer ID, and not the hash obtained when adding the directory. For example:
    https://cloudflare-ipfs.com/ipns/QmV97DGqaaTVn54RH9CLTi9hxXfr57gJQ4zGtyHcVbtfH6

    However, the IPNS-record needs to be updated (published) every few hours manually, and they are much slower / rezolvitsya / ipfs /.

    By the way, IPNS can rezolvit not only CID, but also dnslink-domain records - the site can be opened via the link like https://cloudflare-ipfs.com/ipns/uncleoutrage.com .

    Conclusion

    If you want to learn more about IPFS, read the ivan386 series of excellent articles . They are geeky, and they hardly tell you why an ordinary person might need IPFS (otherwise this article would not exist). Do you want to help in the distribution of IPFS-sites, or to be informed that the domain is bound to an IPFS-gate? Install a browser add-on (for Firefox , for Chrome ) that redirects IPFS sites to your local node. Anti-ban has been distributing a terabyte of PAC files per day over IPFS for several months using Cloudflare gate. It works stably, significantly saves server traffic.




    Also popular now: