Skip to content
Console

Mirror back-to-origin

After you configure mirror back-to-origin, when someone requests a file that doesn't exist in a bucket, S4 fetches it from the origin you specify according to your rules, returns it to the requester, and saves it in the bucket. The next request reads directly from the bucket. It suits migrating existing files from another cloud storage service or a self-hosted server: you don't need to move everything in advance, and your business isn't affected.

To get there, go to Object Storage (对象存储) › Bucket list (桶列表) › click the bucket name › Mirror back-to-origin (镜像回源).

How it works

  1. A requester asks for a file with a GET request.
  2. If the file is in the bucket, it is returned directly with no origin fetch.
  3. If the file isn't in the bucket, S4 requests it from the origin according to the rules.
  4. If the origin returns 200, the content is returned to the requester and saved to the bucket.
  5. All later requests read from the bucket and don't go to the origin. When the file is updated at the origin, the file in the bucket isn't updated.

Add a rule

Open the dialog

Click Add mirror back-to-origin (添加镜像回源).

Enter the origin fetch condition

In File name prefix (文件名前缀), enter a directory that must end with /, for example images/. Enter / for the whole bucket.

Enter the origin address

Choose the protocol and enter the Hostname (主机名) and an optional Directory (目录). The hint box below shows an example address for the current rule.

Submit

Click Submit (提交), and it takes effect immediately.

File name prefixtextRequired

Must end with /. Consecutive /, levels named .., and emoji aren't allowed, and the length can't exceed 128 characters. Each prefix can have only one rule. After saving, the list shows it beginning with /, for example /images/.

Protocolsingle choiceRequiredDefault http

http or https.

HostnametextRequired

The origin domain, for example old.example.com, without http://.

Directorytext

A directory on the origin. It can be empty, and leading and trailing / are removed automatically. The full address assembled from the protocol, hostname, and directory is 10 ~ 256 characters.

You can't add rules while the account has an overdue balance. Rules can't be edited. To change one, Delete (删除) it and add it again.

How addresses map

Matching removes the file name prefix and appends the remaining path to the origin address:

File name prefixOrigin addressRequested in the bucketActual request to the origin
/https://old.example.coma/b.pnghttps://old.example.com/a/b.png
/https://old.example.com/statica/b.pnghttps://old.example.com/static/a/b.png
/images/https://old.example.com/picimages/a/b.pnghttps://old.example.com/pic/a/b.png
/images/https://old.example.com/imagesimages/a/b.pnghttps://old.example.com/images/a/b.png

When the prefix is the same as the origin directory, you still need to fill in Directory, as in the last row.

When multiple rules can match, the one with the longest prefix is used first. If that one doesn't produce a normal result, S4 tries the next matching rule.

Requirements for the origin

ItemDescription
Request methodThe origin receives a GET request
AuthenticationThe origin must allow anonymous reads, and custom request headers aren't supported
Headers and parametersThe requester's headers, cookies, and URL parameters aren't forwarded
User-AgentBegins with @Bitiful/MirrorServer. If the origin has UA or hotlink restrictions, allow it and allow empty Referers
Response200 if the file exists, 404 if it doesn't
Content-TypeSaved to the bucket, so make sure the origin returns the correct type

Files whose names contain ?, #, or % may not fetch correctly from the origin. Migrate them separately.

How it interacts with other features

FeatureBehavior
Public read and signaturesPermissions are checked first, and requests without read permission don't go to the origin
HEAD requestsDon't trigger an origin fetch. If the file isn't in the bucket, S4 returns 404 directly
ListingFiles that haven't been fetched yet don't appear in the file list
Range requestsSupported. The bucket stores the complete file
Image processingProcessing parameters and Styles work from the first origin fetch
Video and animation frame captureThe first request returns 202 MirrorFetching. Request again after the file is saved
CDNAccess through a CDN domain also triggers an origin fetch
DeleteA file deleted from the bucket is fetched from the origin again the next time it's requested. To delete it for good, also delete the file at the origin or remove the rule

Mirror back-to-origin is shared by all users at 1000 QPS. See Limits.

Migration recommendations

Configure origin fetch

Add a rule for the directory to migrate, and test with an address that you know exists at the origin.

Switch your business over

Write new files directly to S4, and switch read addresses to S4 or a CDN that uses it as the origin.

Fill in cold data

Files that are rarely accessed don't trigger an origin fetch. Use Rclone to sync the remaining files.

Delete the rule

After you verify the file counts match, delete the mirror rule, then take the origin offline.

FAQ

It returns 424 MirrorFailed

The origin can't be reached, or it returned a status code other than 200 or 404. The error message states the status code the origin returned. Check the hostname, certificate, hotlink protection, and access restrictions.

It returns 404 NoSuchKey

The origin doesn't have this file, or no rule matched. Check the prefix and directory against the mapping table above.

I see "已经存在相同的前缀配置"

The message means "a configuration with the same prefix already exists". Delete the old rule first, then add it.

The origin updated the file, but the bucket still has the old one

Once a file is saved, S4 no longer goes back to the origin for it. Delete the file in the bucket, and the next request fetches it again.

Can it act only as a proxy, without saving to the bucket?

No. If you only need acceleration and don't need to save files, use the CDN's custom origin.