I'm always excited to take on new projects and collaborate with innovative minds.

Phone

+855 12 282 686

Email

samnangrosady9@gmail.com

Social Links

Open Source Contributions

Rclone: Cloudflare R2 and Nginx Reverse Proxy

Rclone with Cloudflare R2 and Nginx reverse proxy for enhanced cloud storage management and secure data transfer.

Rclone: Cloudflare R2 and Nginx Reverse Proxy

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.

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 🌟

 

Full content:Dev.to

2 min read
Mar 24, 2025
By Samnang Rosady
Share

Leave a comment

Your email address will not be published. Required fields are marked *

Related posts

Aug 15, 2025 • 1 min read
Redis Commander

redis commander: redis monitoring tool

May 08, 2025 • 3 min read
Jinja: The Templating Wizard That Saves Devs From Keyboard Trauma

Jinja: template engine

May 02, 2025 • 2 min read
A Guide to Setting Up Local HTTPS Portals with Docker

Mimicking production environments with HTTPS setups ensures more accur...