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
- A requester asks for a file with a GET request.
- If the file is in the bucket, it is returned directly with no origin fetch.
- If the file isn't in the bucket, S4 requests it from the origin according to the rules.
- If the origin returns 200, the content is returned to the requester and saved to the bucket.
- 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
Enter the origin fetch condition
In File name prefix (文件名前缀), enter a directory that must end with /, for example images/. Enter / for the whole bucket.
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/.
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 prefix | Origin address | Requested in the bucket | Actual request to the origin |
|---|---|---|---|
/ | https://old.example.com | a/b.png | https://old.example.com/a/b.png |
/ | https://old.example.com/static | a/b.png | https://old.example.com/static/a/b.png |
/images/ | https://old.example.com/pic | images/a/b.png | https://old.example.com/pic/a/b.png |
/images/ | https://old.example.com/images | images/a/b.png | https://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
| Item | Description |
|---|---|
| Request method | The origin receives a GET request |
| Authentication | The origin must allow anonymous reads, and custom request headers aren't supported |
| Headers and parameters | The requester's headers, cookies, and URL parameters aren't forwarded |
| User-Agent | Begins with @Bitiful/MirrorServer. If the origin has UA or hotlink restrictions, allow it and allow empty Referers |
| Response | 200 if the file exists, 404 if it doesn't |
| Content-Type | Saved 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
| Feature | Behavior |
|---|---|
| Public read and signatures | Permissions are checked first, and requests without read permission don't go to the origin |
| HEAD requests | Don't trigger an origin fetch. If the file isn't in the bucket, S4 returns 404 directly |
| Listing | Files that haven't been fetched yet don't appear in the file list |
| Range requests | Supported. The bucket stores the complete file |
| Image processing | Processing parameters and Styles work from the first origin fetch |
| Video and animation frame capture | The first request returns 202 MirrorFetching. Request again after the file is saved |
| CDN | Access through a CDN domain also triggers an origin fetch |
| Delete | A 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.
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.