# Bunny.net CDN (Pull Zone)

## Stage 1: Setup Pull Zone&#x20;

### 1) Add new pull zone in Bunny.net

### 2) Create a unique name for the pullzone&#x20;

Example: `mastodoninstancestatic` or similar.

<figure><img src="https://1044007049-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPejQLDNaagNU0AEbyhAu%2Fuploads%2FIjEENdMZWoLGIhmbjmLi%2Fimage.png?alt=media&#x26;token=ac1eada9-2041-4bf7-86b3-f2c0d3ecc969" alt=""><figcaption></figcaption></figure>

### 3) Select `Origin Type URL`

### 4) Update **Origin URL**

Place the original FQDN of your instance in the Original URL.

<figure><img src="https://1044007049-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPejQLDNaagNU0AEbyhAu%2Fuploads%2F3StDWuCdpR1XYmVeFm9P%2Fimage.png?alt=media&#x26;token=d2d3c488-3334-4cc5-829b-caff8827c9c5" alt=""><figcaption></figcaption></figure>

### 5) Select your regions to replicate data

<figure><img src="https://1044007049-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPejQLDNaagNU0AEbyhAu%2Fuploads%2FWegRRlZEAVmqXulywnM3%2Fimage.png?alt=media&#x26;token=4b4db787-bf3a-47e8-b874-326d4b278a29" alt=""><figcaption></figcaption></figure>

### 6) Add new Pull zone

## Stage 2: Configure Pull Zone.

### 1) Force SSL

<figure><img src="https://1044007049-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPejQLDNaagNU0AEbyhAu%2Fuploads%2FPrnXPcUFLT19fa8hQVv5%2Fimage.png?alt=media&#x26;token=ab170c01-e430-4b83-bc38-81dbf6331ae3" alt=""><figcaption></figcaption></figure>

### 2) Setup SafeHop (retries on failures)

<figure><img src="https://1044007049-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPejQLDNaagNU0AEbyhAu%2Fuploads%2FpGsPawDvvpAmG8jDp19B%2Fimage.png?alt=media&#x26;token=437f010c-579a-44e8-815e-96585ef3a007" alt=""><figcaption></figcaption></figure>

### 3) Add additional Headers (CORS)

Add \`,js, gz\` to the Extension list.

Example: \`eot, ttf, woff, woff2, css, js, gz\`

<figure><img src="https://1044007049-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPejQLDNaagNU0AEbyhAu%2Fuploads%2FRi5GawQfSV4rBIUZm7f1%2Fimage.png?alt=media&#x26;token=183f3d0a-4358-407c-924c-5c5b89fa0797" alt=""><figcaption></figcaption></figure>

## Stage 3: Configure Mastodon and NGINX

### 1) NGINX Headers

Add **`Access-Control-Allow-Origin`** header to nginx all locations.\
Example: `add_header Access-Control-Allow-Origin "https://aussocialstatic.b-cdn.net";`

<figure><img src="https://1044007049-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPejQLDNaagNU0AEbyhAu%2Fuploads%2FLWx1POJDIRDevuDFC5b8%2Fimage.png?alt=media&#x26;token=1ac7af17-ffe6-47d6-8a52-1b0796294795" alt=""><figcaption><p>These paths are heavily used for static files... but the header might be required in multiple locations in the nginx conf</p></figcaption></figure>

### 2) Mastodon .env

Add `CDN_HOST` to .env.production&#x20;

Example: `CDN_HOST=https://aussocialstatic.b-cdn.net`

### 3) Reload nginx and restart mastodon.

## Troubleshooting

The OCR (Optical character recognition) might fail if you missed gz from the extension list.

<figure><img src="https://1044007049-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPejQLDNaagNU0AEbyhAu%2Fuploads%2FVlPd3SwQkqoU1qPbyKZ3%2Fimage.png?alt=media&#x26;token=c36134df-7309-464c-b685-2ac8119faa7f" alt=""><figcaption></figcaption></figure>

## Notes

Do we need to add to svg to the CORs?
