IPFS - Interplanetary Filesystem - How to set up a writable IPFS Gateway on a VPS (and configure CORS for cross-domain requests)

in technology •  7 years ago 

IPFS is the Interplanetary Filesystem, it's a new layer of the internet, sort of like the World Wide Web.  But IPFS was built in a Peer To Peer model with the modern Internet in mind.  And it runs on nearly everything, even Raspberry Pi computers.

Currently it only supports static content, you can upload entire websites as long as the website uses only client-side javascript. You can't run code on the server-side (yet).  But there is a dynamic naming system, the IPNS, so that you can update your online content without needing to break old links or create new ones.

It's not just for websites though, there's a ton of cat pictures too.  You can basically store any file-type on IPFS, and it's free to use.

I've set up a writable IPFS Gateway at RelayRouter.com:8080/ipfs/, in order to see anything there you'll need an IPFS hash like this one QmTbhNNgnSzDnQj8mLELcxqZKwUwbzpnHj2iMeqscjpDEF.  It goes at the end of the url like this: http://relayrouter.com:8080/ipfs/QmTbhNNgnSzDnQj8mLELcxqZKwUwbzpnHj2iMeqscjpDEF

![QmTbhNNgnSzDnQj8mLELcxqZKwUwbzpnHj2iMeqscjpDEF.jpg]()

Writing data to IPFS through a gateway can be a little bit tricky though, you will need to post the data from your own html or application, and the hash is what gets returned in an http header named Ipfs-Hash.  (I have no idea why the IPFS developers decided to return the data as an http header instead of just putting it in the body of the response, but there's nothing I can do about it at this point.)

Also, please note that anything you upload to any writable IPFS Gateway will still need to be pinned by you as an IPFS User to make that data persistent.  Otherwise the data that you upload may get wiped at the next garbage collection process, which happens regularly.

Anyway, I believe there should be many more IPFS gateways out there so I wanted to share with you how I set mine up.

First I got a VPS from https://www.ssdnodes.com/startup-specials/ and I chose Ubuntu 16 as the operating system for this VPS.  Then I SSH'd into the VPS from my local PC and entered the following commands:

apt-get update
apt-get install tar wget nano
wget https://dist.ipfs.io/go-ipfs/v0.4.10/go-ipfs_v0.4.10_linux-amd64.tar.gz
tar xfv go-ipfs_v0.4.10_linux-amd64.tar.gz
cd go-ipfs
./install.sh
adduser ipfs
su ipfs
ipfs init
ipfs config --json Discovery.MDNS.Enabled false
ipfs config --json Swarm.AddrFilters '[   "/ip4/10.0.0.0/ipcidr/8",   "/ip4/100.64.0.0/ipcidr/10",   "/ip4/169.254.0.0/ipcidr/16",   "/ip4/172.16.0.0/ipcidr/12",   "/ip4/192.0.0.0/ipcidr/24",   "/ip4/192.0.0.0/ipcidr/29",   "/ip4/192.0.0.8/ipcidr/32",   "/ip4/192.0.0.170/ipcidr/32",   "/ip4/192.0.0.171/ipcidr/32",   "/ip4/192.0.2.0/ipcidr/24",   "/ip4/192.168.0.0/ipcidr/16",   "/ip4/198.18.0.0/ipcidr/15",   "/ip4/198.51.100.0/ipcidr/24",   "/ip4/203.0.113.0/ipcidr/24",   "/ip4/240.0.0.0/ipcidr/4" ]'
ipfs daemon &

At this point we have IPFS installed and running on the VPS, but we can only use it from the command line.  So now for the fun part, we need to make it a writable gateway and enable CORS.  We need to open the file at ~/.ipfs/config.

First make sure your in user "ipfs" instead of "root", if your not sure then type whoami to find out and then type su ipfs if you need to switch to the ipfs user.

Once you've made sure that you're logged in to your VPS as the ipfs user then enter the following command.

nano ~/.ipfs/config

Now we will change line where it reads "Gateway": "/ip4/127.0.0.1/tcp/8080",

We need to change it to "Gateway": "/ip4/0.0.0.0/tcp/8080",

Then scroll down further to the Gateway section.  We need to change it to look like this:

  "Gateway": {
    "HTTPHeaders": {
      "Access-Control-Allow-Headers": [
        "X-Requested-With",
        "Access-Control-Expose-Headers",
        "Range"
      ],
      "Access-Control-Expose-Headers": [
        "Location",
        "Ipfs-Hash"
      ],
      "Access-Control-Allow-Methods": [
        "GET",
        "POST"
      ],
      "Access-Control-Allow-Origin": [
        "*"
      ],
      "X-Special-Header": [
        "Access-Control-Expose-Headers: Ipfs-Hash"
      ]
    },
    "PathPrefixes": [],
    "RootRedirect": "",
    "Writable": true
  },

What we just did there was change the gateway settings to allow writing (posting) and CORS for cross-domain requests.  There only one thing left to do now.  Enter the following command to instruct your VPS to run IPFS every time it boots up:

sed -i -e '$i /bin/su ipfs -c "/usr/local/bin/ipfs daemon &"\n' /etc/rc.local

Then you should reboot your VPS, give it a minute to finish booting, and then check your newly set up gateway by entering its IP Address or URL into a web browser (please keep in mind the default port is 8080) with an IPFS hash, just like at http://relayrouter.com:8080/ipfs/QmTbhNNgnSzDnQj8mLELcxqZKwUwbzpnHj2iMeqscjpDEF but with your own VPS server's address.

Congratulations, you now have your very own IPFS Gateway!  Once it's set up you may want to consider announcing it here on SteemIt so that more people can find more content.

Now, IPFS doesn't just need Gateways, it also needs a Search Engine.  So I would like to encourage anyone who's interested to visit https://github.com/ipfs-search/ipfs-search and check out this awesome project which I totally had nothing at all to do with.  They are in need of hosting and developers.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

My own gateway! About time :)
Upvoted indeed

Follow me @amjad11 & Upvote

Hello guys please register through this link i will be very thankful to you please i need referrals and you can also earn big amount you can check but please help me in getting my target of 40 referrals. I need 40 people to register this link please. I will give you referrals in return but please kindly login through this link.

http://padyredrgi.loan/5317664160364/

Followed and upvoted . Please follow me .

Followed n upvoted. Please follow me .

Nice

I am older and just beginning to code, but this protocol is making it worth it. I can remember when the internet was mostly decentralized and would like to see that again. Thanx!

THANKS

Loading...

Nice informative post with coding implications!!!

Followed n upvoted . Please follow me .

Good job.
Very well explained. Thanks for sharing

I loved your post, a greeting for you, my brother @anomaly

I believe the alt coin Ark will implement this in a future release, interesting concept and hopefully we can see more about this.

Keep me follow and Upvote same for You 😊

Good info nice to know.

Very nice completion of post! @anomaly

I love to computer codes :) Best sharing. Thanks. Follow you.

Thanks for this!

Congratulations @anomaly! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

@anomaly thank you for visiting....

Wonderful post!! The photo and explanations were wonderful ,Cool !!

great content! anomaly

good technology..!

Coding has come a long way since I used to code in COBOL. seems like it was a century ago. LOL!

WOW! Nice work

Nice

I own a few ProxMox Servers for my web hosting company in Atlanta Georgia.
Looks like my weekend will be spent playing with your config. Thank you for this, thank you very much.

Just my two STEEMS Worth.

Damn... you got me lost a bit... more here.

But i got an idea for a new beginning to.. sharing files if i got it right.

I've searched a bit and found about that project started in 2014.

Well, i will read about it and what it means.

But for a brief info, peers are us with our computers and if there is no network?

It is maybe a dumb question, but it is the first time i heard about it...

Cheers

science technology! anomaly

good, can add information for all @anomaly

Best Shared... I share fun videos every day. Please follow me and like to my videos?

I wish I can code :) thanks for upvoting my post (I saw that many times now. thx)

Upvoted!
Gotta admit that I don't have a clue as to how to actually work it, but it sounds really interesting. :-)

I guess I should surf it out on youtube? I'm sure you did a great job of explaining it here, but since it's so completely new to me it's like a foreign language. :-)

Very good post

  ·  7 years ago (edited)

Follow me @amjad11 & Upvote me Thanks

33.jpg

Good job

Nice

cool!

Nice

Woooooow

wonderful thanks for the information

Nice information

Plz visit once to my page.i hope u like my posts

@anomaly thanks for visiting

thanks for the wonderful information like this. i hope to see more of your post. done following upvoting and resteeming your post. :) God bless

Thanks @anomaly for always upvoting my blogs.

tnx for voting my post...plz help

it would be nice if you could alter hashing like on tor network by using something like scallion so sites could look more like for example http://facebookcorewwwi.onion.

i didn't use linux variant, hope i can see a way to got this on windows OS soon :)

Upvoted and followed , you know your stuff !!! Going to certainly read your other posts !!

This post recieved an upvote from minnowpond. If you would like to recieve upvotes from minnowpond on all your posts, simply FOLLOW @minnowpond

flow me and i will flow you

advancing technologically

Thanks for voting.

Nice

good info

thanks for your post bro and also thank you voting me we need to help each other following me please we need to success each other help.

<was here looking for new posts :) thank you tons for all your support :D 💕

WOW very good

nice post

Congratulations. this publication is very interesting and educational, Thank you for sharing it.

Good info

vote, comment, follow done...plz back koren

Anyone can give me steem power

i follow u and also upvote..so,i think u also same with me...i invite u to come my blog and give me ur important upvote

Great work! @anomaly! I wish I could be half as smart as you are! Wonderful, innovative work, keep it up!
Hope you are very well.

Cheers.

awesome post!

Amazing article, amazing technology. Since i am nor an engineer myself, i have instantly shared this article with them. Than you for this post!

Thank you for sharing✨✊

Thanks for sharing @anomaly

nice great pictures

We will support each other

thanks for always supporting my work

Followed n upvoted . Please follow me .

good technology..!

The world is the planet Earth and all life upon it, including human civilization. In a philosophical context, the world is the whole of the earth.so beautifull post..thank you and thank you so much.

Great information!

good job

nice bro

follow me and upvote my [post @tanvirsadatripon

wahou.
Thx for sharing.
I'll try to made my own gateway. I have already a VPS that I use as a steemit gateway (https://steemit.john-at-me.net).
I think, it's important to host those gateways in order to decentralize the new "web".

Amazing blog my friend....

wow...well...thats mindblowing....great research...and i really like the way you put it up @anomaly

hy friend

very nice

Great explanation, thanks for uploading

Hi Anomaly thx for stop and Watch my photos apreciate your vote you have interesting stuff i Will follow you thanks for sharing!

good blog !
follow me @toha

Very useful ,, thanks his information

Congratulations @anomaly! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

This is some FS. Never heard about this in my 18+ years of existences in the UNIX universe!

very good post dear

  ·  7 years ago (edited)

olalalal, the level... :). thanks a lot! all the best.

Congratulations @anomaly! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes received

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

不错,我喜欢

  ·  7 years ago Reveal Comment