Rclone is a powerful command-line tool that allows you to sync, copy, and manage files across multiple cloud storage providers. Cloudflare R2 is an object storage service designed to provide low-latency, high-availability storage without egress fees. By integrating Rclone with Cloudflare R2, you can efficiently manage your cloud storage with ease.
Installation
sudo yum install epel-release
sudo yum -y install fuse rclone -y
ln -s /bin/fusermount /bin/fusermount3
Rclone config
vim ~/.config/rclone/rclone.conf
- rclone.conf
[r2demo]
type = s3
provider = Cloudflare
access_key_id = xxx
secret_access_key = xxxx
endpoint = xxxxx
region = auto
acl = private"
Rclone mount R2 remote to local
Option 1 (Debugging):
rclone mount r2demo:<bucket-name> <local-destination> --vfs-cache-mode off --log-file rclone.log --log-level DEBUG
Option 2:
Run in the background
nohup rclone mount r2demo:<bucket-name> <local-destination> --vfs-cache-mode off --log-file /var/log/rclone.log --log-level NOTICE > /dev/null 2>&1 &
Using --log-file, in case of debugging.
-
--log-level LEVEL
- DEBUG is equivalent to -vv. It outputs lots of debug info - useful for bug reports and really finding out what rclone is doing.
- INFO is equivalent to -v. It outputs information about each transfer and prints stats once a minute by default.
- NOTICE is the default log level if no logging flags are supplied. It outputs very little when things are working normally. It outputs warnings and significant events. ### Symlink
ln -s <local-destination> <project-storage-destination>
Nginx reverse proxy
✅ Faster global delivery due to Cloudflare’s CDN caching.
✅ Potential cost savings by reducing server bandwidth usage.
✅ Decreased load on server, especially for high-traffic websites.
map $uri $new_uploads_uri {
~^/<storage-uri>/(.*)$ //$1;
}
server {
.....
location ^~ /<storage-uri>/ {
resolver 1.1.1.1;
proxy_ssl_server_name on;
proxy_pass https://<public-r2-domain>$new_uploads_uri;
}
}
Sample:
-
< storage-uri >:
wp-content/upload
. We want to reverse from$HOST/wp-content/upload/xxx/xxx/xxx.jpg
to<public-r2-domain>/upload/xxx/xxx/xxx.jpg
Conclusion
By combining Rclone, Nginx, and Cloudflare R2, you can serve static files efficiently with:
✅ Custom domain support
✅ SSL encryption
✅ Caching & compression
✅ No egress fees
🌟 Stay tuned 🌟
Top comments (0)