Skip to content

Commit 1f3d31a

Browse files
Merge pull request #61 from ipfs/feat/nginx-subdomain-config
docs: subdomain gateways
2 parents 4bc415b + 826025c commit 1f3d31a

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

docs/how-to/address-ipfs-on-web.md

+27-14
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ HTTP gateways have worked well since 2015, but they come with a significant set
3030

3131
Tools and browser extensions should detect IPFS content paths and resolve them directly over IPFS protocol. They should use HTTP gateway only as a fallback when no native implementation is available in order to ensure a smooth, backward-compatible transition.
3232

33-
### Gateway types
34-
35-
#### Path gateway
33+
### Path gateway
3634

3735
In the most basic scheme, a URL path used for content addressing is effectively a resource name without a canonical location. The HTTP server provides the location part, which makes it possible for browsers to interpret an IPFS content path as relative to the current server and just work without a need for any conversion:
3836

@@ -41,9 +39,11 @@ https://<gateway-host>.tld/ipfs/<cid>/path/to/resource
4139
https://<gateway-host>.tld/ipns/<ipnsid_or_dnslink>/path/to/resource
4240
```
4341

44-
<aside class="alert alert-info">
45-
In this scheme, all pages share a <a href="https://en.wikipedia.org/wiki/Same-origin_policy" target="_blank">single Origin&nbsp;<i class="fas fa-external-link-square-alt fa-sm"></i></a>, which means this type of gateway should be used when site isolation does not matter.
46-
</aside>
42+
::: danger
43+
In this scheme, all pages share a <a href="https://en.wikipedia.org/wiki/Same-origin_policy" target="_blank">single Origin&nbsp;<i class="fas fa-external-link-square-alt fa-sm"></i></a>, which means this type of gateway should be used only when site isolation does not matter (static content without cookies, local storage or Web APIs that require user permission).
44+
45+
When in doubt, use subdomain gateway instead (see below).
46+
:::
4747

4848
Examples:
4949

@@ -53,7 +53,7 @@ https://ipfs.io/ipfs/QmT5NvUtoM5nWFfrQdVrFtvGfKFmG7AHE8P34isapyhCxX/wiki/Mars.ht
5353
https://ipfs.io/ipns/tr.wikipedia-on-ipfs.org/wiki/Anasayfa.html
5454
```
5555

56-
#### Subdomain gateway
56+
### Subdomain gateway
5757

5858
When [origin-based security](https://en.wikipedia.org/wiki/Same-origin_policy) perimeter is needed, [CIDv1](https://github.com/ipld/cid#cidv1) in Base32 ([RFC4648](https://tools.ietf.org/html/rfc4648#section-6), no padding) should be used in the subdomain:
5959

@@ -64,19 +64,32 @@ Example:
6464
https://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq.ipfs.dweb.link/wiki/
6565
https://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq.ipfs.cf-ipfs.com/wiki/Vincent_van_Gogh.html
6666

67-
<aside class="alert alert-info">
68-
Right now, this type of gateway requires additional configuration (<a href="https://github.com/ipfs/infra/issues/81#issuecomment-461045160" target="_blank">example for Nginx&nbsp;<i class="fas fa-external-link-square-alt fa-sm"></i></a>); however, there is ongoing work to <a href="https://github.com/ipfs/go-ipfs/issues/5982" target="_blank">add native support in the IPFS daemon&nbsp;<i class="fas fa-external-link-square-alt fa-sm"></i></a>.
69-
</aside>
67+
::: tip
68+
69+
For now, this type of gateway requires additional reverse proxy configuration.
70+
As a reference, Nginx config for subdomain gateway at <code>dweb.link</code> is:
71+
72+
```nginx
73+
if ($http_host ~ ^(.+)\.(ipfs|ipns)\.dweb\.link$) {
74+
set $ipfspath /$2/$1;
75+
rewrite "^(.*)$" $ipfspath$1 last;
76+
}
77+
```
78+
79+
There is ongoing work to <a href="https://github.com/ipfs/go-ipfs/issues/6498" target="_blank">add native subdomain support to the IPFS daemon&nbsp;<i class="fas fa-external-link-square-alt fa-sm"></i></a> which will simplify setup and remove the need for path translation at reverse proxy.
80+
:::
7081

71-
#### DNSLink gateway
82+
### DNSLink gateway
7283

7384
The gateway provided by the IPFS daemon understands the `Host` header present in HTTP requests, and will check if [DNSLink](/guides/concepts/dnslink) exists for a specified [domain name](https://en.wikipedia.org/wiki/Fully_qualified_domain_name).
7485
If DNSLink is present, the gateway will return content from a path resolved via DNS TXT record.
7586
This type of gateway provides full [origin isolation](https://en.wikipedia.org/wiki/Same-origin_policy).
7687

7788
Example: [https://docs.ipfs.io](https://docs.ipfs.io) (this website)
7889

90+
::: tip
7991
For a more complete DNSLink guide, including tutorials, usage examples and FAQs, check out [dnslink.io](https://dnslink.io).
92+
:::
8093

8194
## Native URLs
8295

@@ -99,9 +112,9 @@ Example:
99112
ipfs://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/wiki/Vincent_van_Gogh.html
100113
```
101114

102-
<aside class="alert alert-info">
103-
Support for case-insensitive IPNS roots is a <a href="https://github.com/ipfs/go-ipfs/issues/5287" target="_blank">work in progress&nbsp;<i class="fas fa-external-link-square-alt fa-sm"></i></a>.
104-
</aside>
115+
::: tip
116+
Support for case-insensitive IPNS roots is a <a href="https://github.com/ipfs/go-ipfs/issues/5287" target="_blank">work in progress&nbsp;<i class="fas fa-external-link-square-alt fa-sm"></i></a>.
117+
:::
105118

106119
## Further resources
107120

0 commit comments

Comments
 (0)