# More information on how IPFS gateway works

**URL:** <https://discuss.ipfs.tech/t/more-information-on-how-ipfs-gateway-works/2509>\
**Category:** Docs & Tutorials\
**Created:** [April 6, 2018, 3:12am UTC](https://discuss.ipfs.tech/t/more-information-on-how-ipfs-gateway-works/2509 "2018-04-06T03:12:47Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmrobotix](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/dmrobotix/32/871_2.png) [@dmrobotix](https://discuss.ipfs.tech/u/dmrobotix)\
**Post date:** [April 6, 2018, 3:12am UTC](https://discuss.ipfs.tech/t/more-information-on-how-ipfs-gateway-works/2509/1 "2018-04-06T03:12:47Z")

</div>

Hello! I would like to learn more about how the IPFS gateways work to funnel data through [ipfs.io](http://ipfs.io). Is there a particular doc file I could read? How do IPFS nodes setup a gateway that is used by other IPFS nodes?

Thanks!

---

<div class="post-metadata">

**Author:** ![VictorBjelkholm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/victorbjelkholm/32/10_2.png) [@VictorBjelkholm](https://discuss.ipfs.tech/u/VictorBjelkholm)\
**Post date:** [April 6, 2018, 10:56am UTC](https://discuss.ipfs.tech/t/more-information-on-how-ipfs-gateway-works/2509/2 "2018-04-06T10:56:04Z")

</div>

The public gateways are just normal IPFS nodes with the difference that they have automatic GC on.

We currently don’t have any documentation on how to run a public gateway, but basically we’re running NGINX in front of the default gateway of go-ipfs. You can see the NGINX configuration here: [https://github.com/ipfs/infrastructure/blob/master/nginx/nginx.conf](https://github.com/ipfs/infrastructure/blob/master/nginx/nginx.conf)

Anything in specific you want to know? Easier to answer scoped questions than open-ended ones.

---

<div class="post-metadata">

**Author:** ![dmrobotix](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/dmrobotix/32/871_2.png) [@dmrobotix](https://discuss.ipfs.tech/u/dmrobotix)\
**Post date:** [April 7, 2018, 1:06pm UTC](https://discuss.ipfs.tech/t/more-information-on-how-ipfs-gateway-works/2509/3 "2018-04-07T13:06:07Z")

</div>

Thanks for the information.

I guess my biggest confusion stems from my understanding of a web server being a centralized node. So you’ve got [ipfs.io](http://ipfs.io) and then IPFS gateways make it possible to access distributed data via [ipfs.io/ipfs](http://ipfs.io/ipfs) but that’s the part I don’t understand. How do you make it possible to access content from many nodes through [ipfs.io/ipfs](http://ipfs.io/ipfs)?

I apologize if there is an obvious answer to this question, but hoping you could point me in the right direction so I can learn. Thanks!

---

<div class="post-metadata">

**Author:** ![VictorBjelkholm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/victorbjelkholm/32/10_2.png) [@VictorBjelkholm](https://discuss.ipfs.tech/u/VictorBjelkholm)\
**Post date:** [April 7, 2018, 5:50pm UTC](https://discuss.ipfs.tech/t/more-information-on-how-ipfs-gateway-works/2509/4 "2018-04-07T17:50:44Z")

</div>

Right, that’s a good question.

It’s indeed correct that the gateways are (currently) centralized. It’s a important step in our upgrade path of the web to be able to use existing technologies to access distributed content. The trade-off currently is that the HTTP part becomes centralized, as that’s how HTTP works.

So in short without too many details, this is the flow from you adding content on your IPFS node to your browser showing the content from one of our gateways:

1. You add the content on your local IPFS node, getting `$HASH` for future use
2. Your local IPFS advertises the content to all the nodes around it, effectively telling the world that you have `$HASH` available in case anyone needs it
3. You go to `https://ipfs.io/ipfs/$hash` in your browser (or any other public gateway)
4. The HTTP gateway receive a request for `/ipfs/$HASH` and checks if that content is available locally
5. If it’s available locally, just serve the content directly
6. If it’s not available locally, ask the network for which peers the content is available at
7. Once we know some peers that has the content, start downloading the parts of the content from the peers
8. When chunks come in via IPFS, serve what we can via HTTP to the browser
9. Now you can see the content you added at step #1! \o/

Basically the flow is the same within IPFS, but without outputting it via a HTTP endpoint.

---

<div class="post-metadata">

**Author:** ![nothingismagick](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/nothingismagick/32/853_2.png) [@nothingismagick](https://discuss.ipfs.tech/u/nothingismagick)\
**Post date:** [April 7, 2018, 7:45pm UTC](https://discuss.ipfs.tech/t/more-information-on-how-ipfs-gateway-works/2509/5 "2018-04-07T19:45:34Z")

</div>

i saw this link on our forum [here](https://discuss.ipfs.tech/t/a-weekend-with-ipfs-by-will-hill/843), and here is the GIST:

> <https://gist.github.com/claus/1287f47b5fbaaea338ac8a04d02bf258>

---

<div class="post-metadata">

**Author:** ![dmrobotix](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/dmrobotix/32/871_2.png) [@dmrobotix](https://discuss.ipfs.tech/u/dmrobotix)\
**Post date:** [April 7, 2018, 9:09pm UTC](https://discuss.ipfs.tech/t/more-information-on-how-ipfs-gateway-works/2509/6 "2018-04-07T21:09:20Z")

</div>

Thank you, @VictorBjelkholm and @nothingismagick! Really helpful.

---

<div class="post-metadata">

**Author:** ![cloudtinkerer](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/cloudtinkerer/32/2495_2.png) [@cloudtinkerer](https://discuss.ipfs.tech/u/cloudtinkerer)\
**Post date:** [April 8, 2018, 1:57pm UTC](https://discuss.ipfs.tech/t/more-information-on-how-ipfs-gateway-works/2509/7 "2018-04-08T13:57:45Z")

</div>

> [@VictorBjelkholm](#):
>
> Once we know some peers that has the content, start downloading the parts of the content from the peers

For step 7. Once we know some peers that has the content, start downloading the parts of the content from the peers

Does the gateway download and pin the requested content from other peers, and would it mean the data stored will increase proportional to the varying content requested to the gateway?

---

<div class="post-metadata">

**Author:** ![cloudtinkerer](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/cloudtinkerer/32/2495_2.png) [@cloudtinkerer](https://discuss.ipfs.tech/u/cloudtinkerer)\
**Post date:** [April 9, 2018, 12:05am UTC](https://discuss.ipfs.tech/t/more-information-on-how-ipfs-gateway-works/2509/8 "2018-04-09T00:05:26Z")

</div>

Found the answer. In case someone has the same question. Yes, the gateway will download and save the object to the datastore. Though it will not pin it and will be a candidate for GC.

---

<div class="post-metadata">

**Author:** ![VictorBjelkholm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/victorbjelkholm/32/10_2.png) [@VictorBjelkholm](https://discuss.ipfs.tech/u/VictorBjelkholm)\
**Post date:** [April 9, 2018, 3:30am UTC](https://discuss.ipfs.tech/t/more-information-on-how-ipfs-gateway-works/2509/9 "2018-04-09T03:30:43Z")

</div>

Correct! Important to note if you’re planning to run your own gateway: by default the configuration of go-ipfs **does not** have automatic GC turned on and you would have to change that yourself. That’s part of the DatastoreConfig: [https://github.com/ipfs/infrastructure/blob/04b32f7090f6a40b3778fe54054b4eb64a65eb75/ipfs/config.tpl#L6-L14](https://github.com/ipfs/infrastructure/blob/04b32f7090f6a40b3778fe54054b4eb64a65eb75/ipfs/config.tpl#L6-L14)

---

<div class="post-metadata">

**Author:** ![Wabouz](https://avatars.discourse-cdn.com/v4/letter/w/4af34b/32.png) [@Wabouz](https://discuss.ipfs.tech/u/Wabouz)\
**Post date:** [May 1, 2018, 5:49pm UTC](https://discuss.ipfs.tech/t/more-information-on-how-ipfs-gateway-works/2509/10 "2018-05-01T17:49:22Z")

</div>

> [@VictorBjelkholm](#):
>
> GC

I’m sorry, but what does GC mean?

---

<div class="post-metadata">

**Author:** ![nothingismagick](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/nothingismagick/32/853_2.png) [@nothingismagick](https://discuss.ipfs.tech/u/nothingismagick)\
**Post date:** [May 2, 2018, 7:27pm UTC](https://discuss.ipfs.tech/t/more-information-on-how-ipfs-gateway-works/2509/11 "2018-05-02T19:27:56Z")

</div>

garbage collection - clean up memory from stuff that isn’t needed.

---

<div class="post-metadata">

**Author:** ![weihuang1979](https://avatars.discourse-cdn.com/v4/letter/w/b5a626/32.png) [@weihuang1979](https://discuss.ipfs.tech/u/weihuang1979)\
**Post date:** [May 5, 2018, 12:28pm UTC](https://discuss.ipfs.tech/t/more-information-on-how-ipfs-gateway-works/2509/12 "2018-05-05T12:28:24Z")

</div>

could you tell how to setup a new public gateway? thanks

---

<div class="post-metadata">

**Author:** ![jlubbers](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/jlubbers/32/962_2.png) [@jlubbers](https://discuss.ipfs.tech/u/jlubbers)\
**Post date:** [May 5, 2018, 6:59pm UTC](https://discuss.ipfs.tech/t/more-information-on-how-ipfs-gateway-works/2509/14 "2018-05-05T18:59:55Z")

</div>

Correct me if I’m wrong but this worked for me.

Setup an IPFS node on a public server  
Edit the Config file of the node’s address section: change the Gateway to: /ip4/0.0.0.0/tcp/  
“Addresses”: {  
“Gateway”: “/ip4/0.0.0.0/tcp/8080”  
},  
The value of 127.0.0.1 means that only the local machine can access the gatway, but the 0.0.0.0 means any machine can now use the server as a gateway.  
Open up the firewall on the desired port.  
Enjoy the benefits of your own public gateway… faster loads for local added files.

---

<div class="post-metadata">

**Author:** ![myopenledger](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@myopenledger](https://discuss.ipfs.tech/u/myopenledger)\
**Post date:** [December 23, 2018, 7:21pm UTC](https://discuss.ipfs.tech/t/more-information-on-how-ipfs-gateway-works/2509/15 "2018-12-23T19:21:10Z")

</div>

Hi All  
I know its very old post. But, for some reason, I am unable to host my reactjs components in IPFS. Any help?

---

<div class="post-metadata">

**Author:** ![robot9246](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/robot9246/32/5164_2.png) [@robot9246](https://discuss.ipfs.tech/u/robot9246)\
**Post date:** [June 10, 2021, 4:43am UTC](https://discuss.ipfs.tech/t/more-information-on-how-ipfs-gateway-works/2509/16 "2021-06-10T04:43:48Z")

</div>

> [@VictorBjelkholm](#):
>
> 1. Your local IPFS advertises the content to **all the nodes around it,** effectively telling the world that you have `$HASH` available in case anyone needs it

Hello. I want to know that what does "all the nodes around it " excectly mean? It is all the peers which it already has connected to or some peers whose peerID is close to the CID by XOR distance ?  
Thanks

---

<div class="post-metadata">

**Author:** ![hector](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/hector/32/178_2.png) [@hector](https://discuss.ipfs.tech/u/hector)\
**Post date:** [June 10, 2021, 11:15am UTC](https://discuss.ipfs.tech/t/more-information-on-how-ipfs-gateway-works/2509/17 "2021-06-10T11:15:20Z")

</div>

> [@robot9246](#):
>
> It is all the peers which it already has connected to or some peers whose peerID is close to the CID by XOR distance ?

The latter, that is Kademlia-DHT provider record placed in peers found to be XOR-close to the CID.
