---
title: "Publish Your Site With Cloudflare R2"
url: "https://docs.chinaski.net/en/deploy/cloudflare-r2/"
type: "page"
language: "en"
description: "Publish your Chinaski site to Cloudflare R2 step by step: bucket, access keys, custom domain, rewrite rule and deploy settings."
updated: "2026-09-29"
generated: "Markdown rendition of the HTML page at url, built by Chinaski"
---

# Publish Your Site With Cloudflare R2

Chinaski can publish your website to Cloudflare R2. R2 is a file storage service from Cloudflare. Your visitors load the site from Cloudflare, not from the computer where Chinaski runs. This means the computer running Chinaski does not need to be online for your site to work.

Every time you publish, Chinaski builds your site and uploads the files to R2.

This guide takes about 20 to 30 minutes.

## Before you start

You need:

- Chinaski, installed and running. You must be able to open the admin area.
- A Cloudflare account. A free account is enough.
- A domain name, added to your Cloudflare account. For example, `example.com`.
- The web address you want to use for your site. For example, `www.example.com` or `blog.example.com`. In this guide we use `www.example.com`.

> **Important:** Use a separate R2 bucket for each website. When Chinaski publishes, it makes the bucket match your site exactly. **It deletes all other files in the bucket.** Do not store other files in this bucket.

## Step 1: Create a bucket

A bucket is a storage space for your site's files.

1. Sign in to the Cloudflare dashboard at [https://dash.cloudflare.com](https://dash.cloudflare.com).
2. In the menu on the left, select **R2 Object Storage**.
3. Select **Create bucket**.
4. Enter a name for the bucket. Use only lowercase letters, numbers and hyphens. For example: `www-example-com`.
5. For the storage class, select **Standard**.
6. Select **Create bucket**.

Write down the bucket name. You need it in Step 5.

## Step 2: Create access keys

Chinaski needs keys to upload files to your bucket.

1. Go to the **R2 Object Storage** overview page.
2. Select **Manage API tokens**.
3. Select **Create API token**. If Cloudflare asks which type of token you want, select **Account API token**.
4. Enter a name for the token. For example: `Chinaski`.
5. Under **Permissions**, select **Object Read & Write**.
6. Under the bucket scope, select **Apply to specific buckets only**. Then select the bucket you created in Step 1.
7. Select **Create API token**.

Cloudflare now shows your keys. Copy these two values and keep them in a safe place:

- **Access Key ID**
- **Secret Access Key**

> **Important:** Cloudflare shows the Secret Access Key only once. If you lose it, delete the token and create a new one.

You also need your **Account ID**. You can find it on the R2 overview page. It is a long code of letters and numbers.

## Step 3: Connect your domain to the bucket

This step makes your site public at your own web address.

1. Go to **R2 Object Storage** and open your bucket.
2. Select the **Settings** tab.
3. Find **Custom Domains** and select **Add** (or **Connect Domain**).
4. Enter your site's address. For example: `www.example.com`.
5. Follow the steps on the screen to confirm.

Cloudflare creates the DNS record for you. You do not need to change your DNS records yourself.

After a few minutes, the status changes to **Active**. The bucket is now public at this address. You do not need to change any other public access setting.

> **Note:** You may also see a setting called **Public Development URL** (`r2.dev`). This address is only for testing. Do not use it for your real site. Leave it turned off.

## Step 4: Add a URL rewrite rule

Your site's pages are saved as files called `index.html`. For example, the page `www.example.com/about/` is saved as `about/index.html`.

R2 does not find these files automatically. Without this rule, visitors see an error on every page. The rule adds `index.html` to every address that ends with `/`.

1. In the Cloudflare dashboard, open your **domain** (for example, `example.com`). Do not open R2.
2. In the menu on the left, select **Rules**.
3. Create a new **URL Rewrite Rule**. Depending on your dashboard, select one of these:
   - **Rules** > **Overview** > **Create rule** > **URL Rewrite Rule**
   - **Rules** > **Transform Rules** > **Rewrite URL** > **Create rule**
4. Enter a name for the rule. For example: `Site index pages`.
5. Under **If incoming requests match**, select **Custom filter expression**.
6. Select **Edit expression**. Paste this text. Replace `www.example.com` with your site's address:

   ```
   (http.host eq "www.example.com" and ends_with(http.request.uri.path, "/"))
   ```
7. Under **Then**, find **Path**. Select **Rewrite to**, then select **Dynamic**. Paste this text:

   ```
   concat(http.request.uri.path, "index.html")
   ```
8. For **Query**, keep **Preserve**.
9. Select **Deploy**.

## Step 5: Set up Chinaski

1. Open the Chinaski admin area.
2. Go to **Settings** > **General**.
3. In **Site URL**, enter your site's full address. Include `https://`. Do not add `/` at the end. For example: `https://www.example.com`
4. Save.
5. Go to **Settings** > **Deploy**.
6. Fill in these fields:

   | Field | What to enter |
   |---|---|
   | **Enable S3 deploy** | On |
   | **Bucket** | Your bucket name from Step 1. For example: `www-example-com` |
   | **Endpoint** | `https://<ACCOUNT_ID>.r2.cloudflarestorage.com`, replacing `<ACCOUNT_ID>` with your Account ID from Step 2 |
   | **Region** | `auto` |
   | **Access Key** | Your Access Key ID from Step 2 |
   | **Secret Key** | Your Secret Access Key from Step 2 |
   | **Deploy automatically after a successful build** | On |
7. Select **Save Deploy Settings**.

> **Important:** The **Endpoint** must end with `.r2.cloudflarestorage.com`. **Do not add your bucket name at the end.**
>
> Cloudflare sometimes shows the address with the bucket name at the end, like this: `https://<ACCOUNT_ID>.r2.cloudflarestorage.com/<BUCKET_NAME>`
>
> If you copy that address, remove the last `/` and the bucket name. If you do not, Chinaski puts your site in a folder inside the bucket, and visitors see an error on every page.

## Step 6: Test and publish

1. On the **Settings** > **Deploy** page, select **Test S3 Connection**. You should see a success message. If you see an error, check the Bucket, Endpoint and keys again.
2. Publish a page, or edit a page and save it.
3. Wait for the build and upload to finish. The status message at the top of the admin area shows the progress.
4. Open your site in a web browser. For example: `https://www.example.com/`

Check these addresses:

- Your home page: `https://www.example.com/`
- A page inside the site. For example: `https://www.example.com/about/`
- The sitemap: `https://www.example.com/sitemap.xml`

If all of them load, your site is published.

From now on, Chinaski uploads your changes every time you publish. If an upload fails, the previous version of your site stays online. Fix the problem and publish again.

## Troubleshooting

### Every page shows "Error 404" and "Is this your bucket?"

This message comes from R2. It means your domain works, but R2 cannot find the file.

Check these things:

1. **Your files are in a folder.** In Cloudflare, open your bucket and select the **Objects** tab. The file `index.html` must be at the top level, not inside a folder. If your files are inside a folder with your bucket's name, your **Endpoint** has the bucket name at the end. Correct it (see Step 5) and publish again. Chinaski removes the old folder automatically.
2. **The domain is connected to a different bucket.** Open the bucket that contains your files. Select **Settings** and check that your site's address is listed under **Custom Domains**.
3. **The bucket is empty.** Check that **Enable S3 deploy** and **Deploy automatically after a successful build** are both on. Then publish again.

### The home page works, but other pages show an error

The URL rewrite rule is missing or incorrect. Check Step 4. Make sure the rule is turned on, and that the address in the rule is exactly the same as your site's address.

### Pages ending in `index.html` show an error, but only after adding the rule

The rule's filter is too broad. It must apply only to addresses that end with `/`. Check the expression in Step 4, instruction 6.

### "Test S3 Connection" fails

- Check that the **Endpoint** is exactly `https://<ACCOUNT_ID>.r2.cloudflarestorage.com`, with your own Account ID.
- Check that the **Bucket** name is correct. It must not contain `/`.
- Check that you copied both keys completely.
- Check that the API token has **Object Read & Write** permission for this bucket.

### Links on the site point to the wrong address

Check **Site URL** in **Settings** > **General**. It must be your public address, for example `https://www.example.com`. Then publish again.

## Limits

- **Forms and document downloads:** your site is served from R2 only, so R2 cannot send form submissions to Chinaski. If the computer running Chinaski cannot be reached from the internet, contact forms and protected document downloads do not work.
- **Costs:** Cloudflare R2 has a free tier. At the time of writing, it includes 10 GB of storage per month, 1 million upload operations and 10 million read operations per month. Cloudflare does not charge for data sent to your visitors. If you use more than this, Cloudflare charges you. Check the current prices on the [Cloudflare R2 pricing page](https://developers.cloudflare.com/r2/pricing/). The free tier applies only to **Standard** storage.
