Skip to content

Commit e35bb3d

Browse files
Merge pull request #764 from ethersphere/gateway-update
draft of updated gateway content
2 parents 86cbcac + a3d4773 commit e35bb3d

5 files changed

Lines changed: 351 additions & 7 deletions

File tree

docs/develop/gateway.md

Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
---
2+
title: Run a Gateway
3+
id: gateway-proxy
4+
---
5+
6+
This guide explains how to use the [swarm-gateway](https://github.com/ethersphere/swarm-gateway) tool to set up your node in gateway mode. Running your node in gateway mode exposes it publicly, allowing access through any typical browser or http API.
7+
8+
It is divided into several parts:
9+
10+
* Part 1 - Basic setup
11+
* Part 2 - Securing your gateway with TLS
12+
* Part 3 - Optional features
13+
14+
## Part 1 — Running a Swarm Gateway (HTTP, minimal setup)
15+
16+
:::info
17+
Historically, the main tool for running a Swarm HTTP gateway was [gateway-proxy](https://github.com/ethersphere/gateway-proxy), however it is planned to be deprecated in favor of [swarm-gateway](https://github.com/ethersphere/swarm-gateway).
18+
19+
At the time of writing, `gateway-proxy` still contains some features that are not yet implemented in `swarm-gateway` - unless you have a specific need for these features however, `swarm-gateway` is strongly recommended.
20+
:::
21+
22+
This guide describes how to run a Swarm HTTP gateway using `swarm-gateway` and Bee with a minimal configuration.
23+
24+
At the end of this section, the gateway will be reachable at:
25+
26+
```text
27+
http://your-domain.example
28+
```
29+
30+
Swarm content will be accessible at:
31+
32+
```text
33+
http://your-domain.example/bzz/<reference>/
34+
```
35+
36+
:::warning Security notice
37+
This setup uses plain HTTP.
38+
39+
Traffic is not encrypted and any `Authorization` headers can be observed by intermediaries on the network path. This configuration is not suitable for production use.
40+
41+
The purpose of this section is to verify that the gateway is working. HTTPS is added in a later part of the guide.
42+
:::
43+
44+
The guide in this section:
45+
46+
* Runs `swarm-gateway` using Docker
47+
* Connects it to an existing Bee node
48+
* Exposes it publicly over HTTP
49+
50+
:::danger
51+
This part of the guide does not cover setting up TLS, so your gateway will be accessible through plain HTTP, not HTTPS, making it highly insecure. It should not be exposed publicly without first setting up TLS, which is covered in the next section.
52+
:::
53+
54+
### Prerequisites
55+
56+
57+
* A VPS with:
58+
* A public IP address
59+
* Port **80** open
60+
* Docker
61+
* A domain for hosting your gateway publicly
62+
* A running Bee node in Docker
63+
* A valid stamp batch
64+
65+
### 1. Configure DNS for your domain
66+
67+
Create an A record in your DNS provider:
68+
69+
```text
70+
your-domain.example -> <your-server-ip>
71+
```
72+
73+
ADD SCREENSHOT
74+
75+
After DNS propagation, verify that the domain resolves to your server (this may take some time, to verify more quickly, try pinging from a different machine or VPS):
76+
77+
```bash
78+
ping your-domain.example
79+
```
80+
81+
### 2. Create a Docker network
82+
83+
The gateway container must be able to communicate with your Bee node, for this, both containers must be on the same Docker network.
84+
85+
Create a network and attach the Bee container to it:
86+
87+
```bash
88+
docker network create swarm-net
89+
docker network connect swarm-net bee-1
90+
```
91+
92+
Verify:
93+
94+
```bash
95+
docker network inspect swarm-net
96+
```
97+
98+
The output should list `bee-1` as an attached container.
99+
100+
### 3. Pull the gateway image
101+
102+
```bash
103+
docker pull ethersphere/swarm-gateway:0.1.3
104+
```
105+
106+
### 4. Run the gateway
107+
108+
Start the gateway container:
109+
110+
```bash
111+
docker run -d --restart unless-stopped \
112+
--name swarm-gateway \
113+
--network swarm-net \
114+
-p 80:3000 \
115+
-e HOSTNAME="your-domain.example" \
116+
-e BEE_API_URL="http://bee-1:1633" \
117+
-e DATABASE_CONFIG="{}" \
118+
ethersphere/swarm-gateway:0.1.3
119+
```
120+
121+
In this configuration, database-backed features such as subdomain rewrites and moderation are not configured.
122+
123+
### 5. Verify operation
124+
125+
From your local machine (not the server on your VPS):
126+
127+
```bash
128+
curl http://your-domain.example/health
129+
```
130+
131+
Expected output:
132+
133+
```text
134+
OK
135+
```
136+
137+
### 6. Test with uploaded content
138+
139+
Upload a file using Bee:
140+
141+
```bash
142+
echo "hello swarm" > test.txt
143+
swarm-cli upload test.txt
144+
```
145+
146+
This will print a Swarm reference.
147+
148+
Open the file through the gateway:
149+
150+
```text
151+
http://your-domain.example/bzz/<REFERENCE>/
152+
```
153+
154+
The file contents should be returned.
155+
156+
### 7. Optional: restrict uploads using authentication
157+
158+
By default, the gateway allows anyone to upload content using your Bee node.
159+
160+
To restrict uploads, set:
161+
162+
* `AUTH_SECRET` — a long random string
163+
* `SOFT_AUTH=true` — only require authentication for POST requests
164+
165+
Example (add these lines to the `docker run` command):
166+
167+
```bash
168+
-e AUTH_SECRET="replace-with-a-long-random-secret" \
169+
-e SOFT_AUTH="true" \
170+
```
171+
172+
At this point, you have:
173+
174+
* A working Swarm HTTP gateway
175+
* Connected to your Bee node
176+
* Exposing content publicly over `/bzz/<reference>`
177+
178+
The setup is intentionally minimal and suitable for testing and development, however without TLS, it is not secure and should never be used in production or publicly exposed.
179+
180+
The next section explains how to enable TLS so that your gateway can be securely accessed through HTTPS.
181+
182+
183+
## Part 2 — Securing your gateway with TLS (HTTPS)
184+
185+
This section explains how to secure your gateway using **TLS (HTTPS)** with **Caddy**.
186+
187+
Caddy is used here as a front-facing web server that automatically manages TLS certificates and forwards traffic to `swarm-gateway`.
188+
189+
In this setup:
190+
191+
* Caddy is responsible only for HTTPS and certificate management
192+
* `swarm-gateway` continues to act as the application gateway and reverse proxy for Bee
193+
194+
At the end of this section, your gateway will be reachable at:
195+
196+
```text
197+
https://your-domain.example
198+
```
199+
200+
And all HTTP traffic will be automatically redirected to HTTPS.
201+
202+
### Prerequisites
203+
204+
In addition to the prerequisites from Part 1:
205+
206+
* Your domain must already point to your VPS IP address
207+
* Ports **80** and **443** must be open on your VPS firewall
208+
209+
210+
### 1. Reconfigure the gateway to not expose port 80
211+
212+
Caddy will become the public entry point, so `swarm-gateway` should no longer be exposed directly.
213+
214+
Stop and remove the existing container:
215+
216+
```bash
217+
docker stop swarm-gateway
218+
docker rm swarm-gateway
219+
```
220+
221+
Recreate it **without** publishing port 80:
222+
223+
```bash
224+
docker run -d --restart unless-stopped \
225+
--name swarm-gateway \
226+
--network swarm-net \
227+
-e HOSTNAME="your-domain.example" \
228+
-e BEE_API_URL="http://bee-1:1633" \
229+
-e DATABASE_CONFIG="{}" \
230+
ethersphere/swarm-gateway:0.1.3
231+
```
232+
233+
The gateway is now only accessible from within the Docker network.
234+
235+
236+
### 2. Create a Caddy configuration
237+
238+
Create a directory for the Caddy configuration:
239+
240+
```bash
241+
mkdir -p ~/caddy
242+
cd ~/caddy
243+
```
244+
245+
Create a file named `Caddyfile`:
246+
247+
```bash
248+
nano Caddyfile
249+
```
250+
251+
Add the following configuration (replace the domain):
252+
253+
```caddy
254+
your-domain.example {
255+
reverse_proxy swarm-gateway:3000
256+
}
257+
```
258+
259+
### 3. Run Caddy
260+
261+
Start Caddy in Docker and attach it to the same Docker network:
262+
263+
```bash
264+
docker run -d --restart unless-stopped \
265+
--name caddy \
266+
--network swarm-net \
267+
-p 80:80 \
268+
-p 443:443 \
269+
-v $HOME/caddy/Caddyfile:/etc/caddy/Caddyfile \
270+
-v caddy_data:/data \
271+
-v caddy_config:/config \
272+
caddy:2
273+
```
274+
275+
Caddy will automatically:
276+
277+
* Obtain a TLS certificate for your domain
278+
* Renew it before it expires
279+
* Redirect all HTTP traffic to HTTPS
280+
281+
282+
### 4. Verify operation
283+
284+
From your local machine:
285+
286+
```bash
287+
curl https://your-domain.example/health
288+
```
289+
290+
Expected output:
291+
292+
```text
293+
OK
294+
```
295+
296+
You can also verify that HTTP is redirected to HTTPS:
297+
298+
```bash
299+
curl -I http://your-domain.example/health
300+
```
301+

docs/develop/image.png

-54.9 KB
Binary file not shown.

docs/develop/introduction.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ This is the go-to starting point for web3 developers who want to build with Swar
8080
<span class="hub-card__cta">Open Guide</span>
8181
</a>
8282
</li>
83+
<li class="hub-card">
84+
<a class="hub-card__link" href="/docs/develop/gateway-proxy">
85+
<h3 class="hub-card__title">Run a Gateway</h3>
86+
<p class="hub-card__desc">
87+
Run your own Swarm HTTP gateway to serve content from the network and make it accessible to browsers and other HTTP clients.
88+
</p>
89+
<span class="hub-card__cta">Open guide</span>
90+
</a>
91+
</li>
8392
<!--
8493
<li class="hub-card">
8594
<a class="hub-card__link" href="/docs/develop/dynamic-content">

docs/develop/tools-and-features/gateway-proxy.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,50 @@ title: Gateway Proxy
33
id: gateway-proxy
44
---
55

6-
The [Gateway Proxy tool](https://github.com/ethersphere/gateway-proxy) is more than just a proxy, it offers a range of useful functionalities for node operators and Swarm developers. For more in depth documentation of its features, refer to its [README doc](https://github.com/ethersphere/gateway-proxy/blob/master/README.md) on GitHub.
6+
The [Swarm Gateway](https://github.com/ethersphere/swarm-gateway) is the standard way to expose a Bee node over HTTP.
77

8-
### Public Gateway
8+
:::info
9+
Another tool which is currently popular for running Bee in gateway mode is [Gateway Proxy](https://github.com/ethersphere/gateway-proxy). It offers several features not yet included in Swarm Gateway. However, since it is set for deprecation, unless you have a specific need, it is recommended to use Swarm Gateway instead.
10+
:::
911

10-
The tool can be used to set up a public gateway which can be used to host public facing applications or websites to users on the web who aren't running Bee nodes.
12+
It acts as a reverse proxy that runs in front of a Bee node, allowing you to expose your node publicly. It proxies the Bee HTTP API and content endpoints, while optionally adding access control, postage batch auto-buy, and other optional features.
13+
14+
### Public Access to Swarm
15+
16+
A gateway can be used to run a public endpoint that allows users to:
17+
18+
* Access content stored on Swarm using standard HTTP URLs
19+
* Browse websites hosted on Swarm
20+
* Interact with Swarm through a familiar web interface
21+
22+
This makes Swarm content accessible to any web client, even if the user is not running a Bee node locally.
23+
24+
### Authentication, Access Control, and Policy
25+
26+
The Swarm Gateway also acts as an access control and content moderation layer in front of a Bee node.
27+
28+
Rather than exposing a Bee node directly to the public internet, the gateway allows operators to place a managed HTTP interface in front of it. Through this interface, the gateway can:
29+
30+
* Expose a Bee node through a single public HTTP endpoint
31+
* Restrict or control uploads and other sensitive operations
32+
* Require authentication for selected endpoints or request types
33+
* Apply basic access control and usage policies before requests reach the Bee node
34+
35+
This makes it possible to run public, private, or semi-public gateways while retaining control over how the underlying Bee node is used.
36+
37+
For production deployments, the gateway is typically run behind an HTTPS reverse proxy to ensure encrypted connections.
1138

1239
### Stamp Management
1340

14-
In addition to acting as a proxy, it also includes convenient features for managing stamps such as automatically buying new stamps or automatically extending the life of existing stamps.
41+
The Swarm Gateway can optionally manage postage stamps on behalf of the operator, including:
42+
43+
* Automatically buying new batches
44+
* Monitoring batch usage and expiration
45+
* Keeping batches alive based on specified TTL
46+
47+
This is especially useful for gateways that accept uploads from users or applications.
1548

16-
### Security
1749

18-
Authentication can also be enabled so that only authorized requests are fulfilled. This is a useful feature for protecting your node if its API endpoint is publicly exposed.
50+
## Setting up a Gateway
1951

52+
For a step by step guide on setting up a gateway yourself, refer to the [guide in the Develop on Swarm section](/docs/develop/gateway-proxy/).

sidebars.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ module.exports = {
9191
'develop/upload-and-download',
9292
'develop/host-your-website',
9393
'develop/files',
94-
'develop/routing',
94+
'develop/routing',
95+
'develop/gateway-proxy',
9596
// 'develop/dynamic-content',
9697
'develop/act',
9798
],

0 commit comments

Comments
 (0)