Jump to content

How to run an IPFS Website directly from IPFS and Cloudflare, no Nginx Proxy Pass, Cluster to Decentralize [GUIDE]


buzzkillb
 Share

Recommended Posts

The goal here is to setup 2 or more vps's to run IPFS in cluster mode. The IPFS daemons will stay in sync to distribute the files so its always up. Then use a typical domain name to serve the hash using Cloudflare gateway on Cloudflare's dashboard. From there a typical web browser sees your domain like usual, but behind the scenes can still use the IPFS Browser to directly see the website.

create user denarius or whoever you want, but notice in the systemd files User=whoeveryoucreated

adduser denarius
usermod -aG sudo denarius

exit

If you are using ssh keys already

ssh-copy-id [email protected]

login

ssh [email protected]

install ipfs (Snapcraft), since snap might have to logout and back in after the sudo apt install snapd part. Mainly just wanted to show how to use snap IPFS daemon.
https://snapcraft.io/ipfs

sudo apt update
sudo apt install snapd
sudo snap install ipfs
ipfs version

ipfs init

systemd service

sudo nano  /etc/systemd/system/ipfs.service
[Unit]
Description=IPFS daemon
After=network.target

[Service]
### Uncomment the following line for custom ipfs datastore location
# Environment=IPFS_PATH=/path/to/your/ipfs/datastore
User=denarius
ExecStart=/snap/bin/ipfs daemon                        
Restart=always    

[Install]
WantedBy=multi-user.target

sudo systemctl restart ipfs
sudo systemctl status ipfs
sudo systemctl enable ipfs

install ipfs cluster ctl

https://dist.ipfs.io/#ipfs-cluster-ctl

wget https://dist.ipfs.io/ipfs-cluster-ctl/v0.13.0/ipfs-cluster-ctl_v0.13.0_linux-amd64.tar.gz
tar -xzvf ipfs-cluster-ctl_v0.13.0_linux-amd64.tar.gz
cd ipfs-cluster-ctl
sudo cp ipfs-cluster-ctl /usr/local/bin/


install ipfs cluster service

https://dist.ipfs.io/#ipfs-cluster-service

wget https://dist.ipfs.io/ipfs-cluster-service/v0.13.0/ipfs-cluster-service_v0.13.0_linux-amd64.tar.gz
tar -xzvf ipfs-cluster-service_v0.13.0_linux-amd64.tar.gz
cd ipfs-cluster-service
sudo cp ipfs-cluster-service /usr/local/bin/

initialize ipfs cluster

ipfs-cluster-service init

the secret to use across all the clusters is in ~/.ipfs-cluster/service.json
example a2e2f791d26a04e76cbea370696964614a574a4265593aeaf4

systemd service

sudo nano  /etc/systemd/system/ipfsc.service
[Unit]
Description=IPFS Cluster daemon
After=network.target

[Service]
### Uncomment the following line for custom ipfs datastore location
# Environment=IPFS_PATH=/path/to/your/ipfs/datastore
User=denarius
ExecStart=/usr/local/bin/ipfs-cluster-service daemon                        
Restart=always    

[Install]
WantedBy=multi-user.target

Start, Status and Enable service

sudo systemctl restart ipfsc
sudo systemctl status ipfsc
sudo systemctl enable ipfsc

in status look for a line like this, this will be your bootstrap for the other nodes in the cluster
/ip4/23.94.107.170/tcp/9096/p2p/12D3KooWL6FJgyiY3BUMx8PXpqCK3B6Qcn6X5dPPtGvgAaB7gTxW

how bootstrap looks in systemd on the helpers

sudo nano  /etc/systemd/system/ipfsc.service
[Unit]
Description=IPFS Cluster daemon
After=network.target

[Service]
### Uncomment the following line for custom ipfs datastore location
# Environment=IPFS_PATH=/path/to/your/ipfs/datastore
User=denarius
ExecStart=/usr/local/bin/ipfs-cluster-service daemon --bootstrap /ip4/23.94.107.170/tcp/9096/p2p/12D3KooWL6FJgyiY3BUMx8PXpqCK3B6Qcn6X5dPPtGvgAaB7gTxW                     
Restart=always    

[Install]
WantedBy=multi-user.target

then to pin we use ipfs-cluster-ctl

ipfs-cluster-ctl peers ls

Add some random example file. Like nano example.txt, "this is a test"

ipfs-cluster-ctl add example.txt
ipfs-cluster-ctl pin ls

now go to, to add the newly created hash directly to cloudflare to serve through their gateway. I see a 50mb limit on files, so be aware of this if making a website.

https://www.cloudflare.com/distributed-web-gateway/

Add the CNAME and TXT Record like below

image.thumb.png.946b43c6ad5be48da1313083710fdccf.png

Then back on the cloudflare link above, input your domain name, and Submit.

image.png.281e7d49a3b222786025a51736f05c3a.png

Now you have an instant website serving using the Cloudflare IPFS gateway and a cluster of IPFS daemons keeping the files in sync. The website will also stay fully decentralized using IPFS directly because of that initial cluster we setup above.

An example which I am not going to keep up forever. But wanted to show how this looks across different browsers and URLs. Just remember no nginx proxy pass is being used in this guide.

ipfs-cluster-ctl add -r ~/website

which gave me a hash of QmSrrb571Gm1RLvxHePEMXfuzjTG1nbCNb5PrZutJLde5L spread between the cluster

Some Examples

then in Brave Nightly as an example I can type

ipfs://QmSrrb571Gm1RLvxHePEMXfuzjTG1nbCNb5PrZutJLde5L

Which since directly seems slow, and still learning how this works, appears like this.

image.png.3585514e0df59fe4786b1cf8c45e6891.png

This is how same page looks using Firefox with IPFS Companion, going directly through the hash

image.png.81dddbe54633d7d3276cbb35e24f638a.png

And how a typical user would see in Chrome going directly to denarius.guide

image.png.88688c2f962245c97364709ad053ea4d.png

  • The D 1

If you enjoy my content please consider donating to the Denarius creator - https://www.patreon.com/carsenk
Join Denarius Discord - https://discord.gg/JQEmXwb

Link to comment
Share on other sites

  • Ghost changed the title to How to run an IPFS Website directly from IPFS and Cloudflare, no Nginx Proxy Pass, Cluster to Decentralize [GUIDE]
  • 3 weeks later...

To run under a subdomain using Cloudflare to show your new IPFS hash. In this example we use example subdomain. https://example.denarii.link/

image.thumb.png.9b0684416457e293ebf994e8e3d02e43.png

Once you set the IPFS hash don't forget to go to https://www.cloudflare.com/distributed-web-gateway/

and then fill out the box for your certificate.

image.thumb.png.30a375312f73d6c63b9d9aded89a44cb.png

If you enjoy my content please consider donating to the Denarius creator - https://www.patreon.com/carsenk
Join Denarius Discord - https://discord.gg/JQEmXwb

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...