Skip to content

Commit

Permalink
Spelling and formatting updates
Browse files Browse the repository at this point in the history
  • Loading branch information
svenja11 committed Jan 17, 2025
1 parent 2a62fca commit 2f9f6ce
Showing 1 changed file with 80 additions and 56 deletions.
136 changes: 80 additions & 56 deletions tutorials/hetzner-object-storage-custom-domain/01.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
SPDX-License-Identifier: MIT
path: "/tutorials/hetzner-object-storage-custom-domain"
slug: "hetzner-object-storage-custom-domain"
date: "2025-01-05"
title: "Setup custom domain with S3-compatible object storage"
short_description: "This tutorial explains how to setup custom domain for S3-compatible object storage using reverse proxy."
date: "2025-01-17"
title: "Setup custom domain for S3-compatible object storage via reverse proxy"
short_description: "This tutorial explains how to setup custom domains for S3-compatible object storage using reverse proxy."
tags: ["Custom domain", "Reverse proxy", "Object Storage"]
author: "Ivan Zaitsev"
author_link: "https://github.com/ivan-zaitsev"
Expand All @@ -18,31 +18,31 @@ cta: "cloud"

## Introduction

This tutorial will guide you to setup custom domain for S3-compatible object storage using reverse proxy.
The advantages of custom domain is to enable seamless integration with existing infrastructure or services under a unified domain.
This tutorial will guide you to setup a custom domain for S3-compatible object storage using reverse proxy.
The advantages of a custom domain are to enable seamless integration with existing infrastructure or services under a unified domain.

A custom domain can be configured in various ways, such as using a CNAME record or a reverse proxy.
There are different ways to configure a custom domain, such as using a CNAME record or a reverse proxy.
This tutorial focuses on configuring a custom domain using a reverse proxy.

**Prerequisites**

* A server (e.g. with [Hetzner Cloud](https://www.hetzner.com/cloud/))
* A S3-compatible bucket (e.g. with [Hetzner](https://www.hetzner.com))
* An S3-compatible bucket (e.g. with [Hetzner](https://www.hetzner.com/storage/object-storage/))
* A domain you want to use (e.g. `storage.example.com`).

## Step 1 - Create Object Storage Bucket

Create a S3-compatible bucket.
Create an S3-compatible bucket.
With Hetzner, see the getting started "[Creating a Bucket](https://docs.hetzner.com/storage/object-storage/getting-started/creating-a-bucket)".
Make sure it is set to public access permissions. No much benefit of using custom domain for private buckets.
Make sure it is set to public access permissions. Not much benefit to using a custom domain for private buckets.

Create S3 credentials to access your bucket.
With Hetzner, see the getting started "[Generating S3 keys](https://docs.hetzner.com/storage/object-storage/getting-started/generating-s3-keys)".

## Step 2 - Create Server

Create a new server.
With Hetzner, see the getting started "[Creating a Server](https://docs.hetzner.com/cloud/servers/getting-started/creating-a-server)").
With Hetzner, see the getting started "[Creating a Server](https://docs.hetzner.com/cloud/servers/getting-started/creating-a-server)".
To install Docker and Docker Compose, follow the [official Docker documentation](https://docs.docker.com/engine/install/).

## Step 3 - Deploy Caddy
Expand All @@ -52,65 +52,84 @@ SSH to your server `ssh root@<server-ip>`.
Create a directory for your Docker Compose files and folders for the persistent storage of the Caddy container:

```bash
mkdir -p /opt/caddy/data
sudo mkdir -p /opt/caddy/data
```

### Step 3.1 - Create docker deployment and configuration files

`vim /opt/caddy/compose.yaml`

```yaml
services:
caddy:
container_name: caddy
image: caddy:latest
restart: unless-stopped
ports:
- 80:80
- 443:443
volumes:
- ./data/Caddyfile:/etc/caddy/Caddyfile
- ./data/certs:/certs
- ./data/config:/config
- ./data/data:/data
- ./data/sites:/srv
```
`vim /opt/caddy/data/Caddyfile`

```text
storage.example.com {
tls {
issuer acme {
dir https://acme-v02.api.letsencrypt.org/directory
}
}
}
storage.example.com:443 {
reverse_proxy https://fsn1.your-objectstorage.com {
header_up Host {http.reverse_proxy.upstream.hostport}
header_up X-Forwarded-Host {host}
### Step 3.1 - Create Docker deployment and configuration files

* Add a Docker compose file

```bash
sudo vim /opt/caddy/compose.yaml
```
Add the following content:
```yaml
services:
caddy:
container_name: caddy
image: caddy:latest
restart: unless-stopped
ports:
- 80:80
- 443:443
volumes:
- ./data/Caddyfile:/etc/caddy/Caddyfile
- ./data/certs:/certs
- ./data/config:/config
- ./data/data:/data
- ./data/sites:/srv
```
<br>
* Add a Caddyfile
```bash
sudo vim /opt/caddy/data/Caddyfile
```
Add the following content:

> Replace `storage.example.com` with your own domain.
> Replace `fsn1.your-objectstorage.com` with the endpoint of your object storage bucket. If the bucket name comes after the endpoint (e.g. `https://s3-endpoint.example.org/<bucket_name>`) add your endpoint without the bucket name.
```text
storage.example.com {
tls {
issuer acme {
dir https://acme-v02.api.letsencrypt.org/directory
}
}
reverse_proxy https://<bucket_name>.fsn1.your-objectstorage.com {
#reverse_proxy https://s3-endpoint.example.org {
header_up Host {http.reverse_proxy.upstream.hostport}
header_up X-Forwarded-Host {host}
}
}
}
```
```

### Step 3.2 - Start Caddy

```bash
cd /opt/caddy
docker compose up -d
docker ps
```

**Note:**
After the Docker container started, you can access your files via `storage.example.com`.

The request url would be `https://storage.example.com/bucket-name/object.txt`.
It is equivalent to `https://fsn1.your-objectstorage.com/bucket-name/object.txt`.
If your bucket name comes after the endpoint, note:

### Step 3.3 - Create kubernetes deployment and configuration files (Optional)
The request URL would be `https://storage.example.com/<bucket_name>/object.txt`.
It is equivalent to `https://s3-endpoint.example.org/<bucket_name>/object.txt`.

Assuming you already have configured kubernetes, gateway api.
### Step 3.3 - Create Kubernetes deployment and configuration files (Optional)

Assuming you already have configured Kubernetes, [gateway API](https://gateway-api.sigs.k8s.io/guides/#installing-gateway-api).

> Replace `storage.example.com` with your own domain.
> Replace `fsn1.your-objectstorage.com` with the endpoint of your object storage bucket. If the bucket name comes after the endpoint (e.g. `https://s3-endpoint.example.org/<bucket_name>`) add your endpoint without the bucket name.
```yaml
apiVersion: v1
Expand Down Expand Up @@ -171,7 +190,8 @@ metadata:
data:
Caddyfile: |
storage.example.com:80 {
reverse_proxy https://fsn1.your-objectstorage.com {
reverse_proxy https://<bucket_name>.fsn1.your-objectstorage.com {
#reverse_proxy https://s3-endpoint.example.org {
header_up Host {http.reverse_proxy.upstream.hostport}
header_up X-Forwarded-Host {host}
}
Expand Down Expand Up @@ -201,6 +221,10 @@ spec:
weight: 100
```
## Conclusion
You should now be able to access the contents of your S3-compatible object storage via a custom domain.
##### License: MIT
<!--
Expand Down

0 comments on commit 2f9f6ce

Please sign in to comment.