FA Dev Tools

English中文

Publish a Local Folder to the Web — R2 vs S3 vs EC2

infra/publish-folder-to-web-r2-s3-ec2 · By Derek Lam · Updated · 31 views · Tags: infra, cloudflare, r2, s3, aws, ec2, nginx, rclone

Written with claude-opus-5-5


TL;DR

  • Winner for "drop a file in a folder, get a public URL": Cloudflare R2 + rclone, on a custom domain like r2.fishapple.com.
  • R2 beats S3 because downloads cost $0 (S3 Sydney: ~$0.114/GB) and custom-domain HTTPS is one click.
  • Use an EC2 box + nginx only when you need a browsable folder listing or a password on it.
  • S3 works too when you want it on AWS: public.fishapple.com is an S3 bucket behind Cloudflare, and a change shows up there in about 4 seconds.
  • Verdict: R2 bucket on a custom domain, synced one way by rclone. Run rclone from a file watcher for near real time, or from Task Scheduler every 5 minutes.

The goal

A folder on a desktop PC (D:\my-drive\r2-data or D:\my-drive\s3-public here) syncs on its own to the cloud, and every file in it can be opened from the internet at https://<host>.fishapple.com/<path>. One way: the PC is the source of truth.

Which program does the syncing is a separate choice, compared in Sync Tools Compared. In short: rclone talks to R2 and S3 directly, and Syncthing can't.

Every file in the folder can be downloaded by anyone who has its URL, with no password. A bucket has no folder listing, so people only find what you link them to, but never put anything private in the folder.

Which one

flowchart TD
  A["Need a browsable folder listing<br/>or a password?"] -->|Yes| E["EC2 + nginx<br/>autoindex + auth_basic"]
  A -->|No| B["DNS zone on Cloudflare?"]
  B -->|Yes| D["Must it be on AWS?"]
  D -->|No| R["R2 + custom domain"]
  D -->|Yes| SC["S3 website<br/>behind Cloudflare proxy"]
  B -->|No| C["Already all-in on AWS?"]
  C -->|Yes| S["S3 + CloudFront"]
  C -->|No| R

Option 1 — Cloudflare R2 bucket on a custom domain (chosen)

HTTPS on your domainBuilt in. Connect r2.fishapple.com under the bucket's Custom Domains; Cloudflare makes the DNS record and the cert
Storage$0.015/GB-month, first 10 GB-month free
Downloads (egress)$0
Requests1M Class A (writes, lists) and 10M Class B (reads) free per month
Folder listingNo. People open files by direct link
PasswordNo (would need Cloudflare Access or a Worker in front)
Sync toolrclone (provider = Cloudflare), or anything that speaks the S3 API
SetupTurn on R2 in the dashboard (needs a payment method), create the bucket, connect the domain, make a bucket-scoped API token

Fits best when the DNS zone is already on Cloudflare: no certs, no origin server, nothing to patch.

Option 2 — AWS S3 bucket as a static website

HTTPS on your domainS3 website endpoints are HTTP only. Put CloudFront in front, or a proxied (orange cloud) Cloudflare CNAME to the website endpoint. With Cloudflare, add a Configuration Rule that sets SSL to Flexible for that hostname only. It works on the free plan, and the rest of the zone keeps Full
Bucket nameMust be exactly the hostname (public.fishapple.com) for a CNAME to the website endpoint to work
Storage~$0.025/GB-month (Standard, ap-southeast-2)
Downloads~$0.114/GB after AWS's 100 GB/month free tier. A CDN in front cuts this
Folder listingNo
Public accessOn that bucket, turn off the two policy settings of Block Public Access (BlockPublicPolicy, RestrictPublicBuckets) and add a public-read bucket policy (s3:GetObject on bucket/*). The two ACL settings can stay on
CachingSet Cache-Control on each upload (max-age=60 here). Without it, Cloudflare keeps images and PDFs at its edge for its default 2 hours, so an edit shows up late
Sync toolrclone, aws s3 sync, or WinSCP (which can't set Cache-Control)

Never make a bucket public that also holds deploy files, env files or backups. Turning off Block Public Access applies to the whole bucket.

Option 3 — Sync to an EC2 box, serve it with nginx

HTTPS on your domainThe same as any other vhost on the box (here: Cloudflare Origin CA cert + nginx)
CostNo new service, but egress is EC2's ~$0.114/GB and the files use the box's disk
Folder listingYes, autoindex on;
PasswordYes, auth_basic
Sync toolrsync over SSH, rclone's SFTP backend, WinSCP, or Syncthing on both ends
RisksTies the folder to one box's uptime; a growing folder can fill a small data disk shared with databases

Pick this only when browsing or a password matters more than having nothing to run.

Side by side

R2 + custom domainS3 websiteEC2 + nginx
HTTPS on own domain✅ built in⚠️ needs CloudFront, or the Cloudflare proxy + a Flexible SSL rule✅
Download cost✅ $0❌ ~$0.114/GB❌ ~$0.114/GB
Storage cost$0.015/GB-mo, 10 GB free~$0.025/GB-moEBS gp3 ~$0.096/GB-mo, billed on the disk's full size, not what's used
Folder listing❌❌✅
Password protection⚠️ via Cloudflare Access⚠️ via CloudFront + signed URLs✅ basic auth
Depends on a server you run✅ no✅ no❌ yes
Easiest sync from Windowsrclonerclone / aws s3 syncrclone SFTP / WinSCP
Sync direction⚠️ one way, PC → bucket (rclone sync); two-way only with rclone bisync⚠️ one way, PC → bucket (aws s3 sync, rclone sync); two-way only with rclone bisync✅ one way (rsync, rclone) or two-way (Syncthing on both ends)
Change files from the web❌ download only❌ download only❌ download only, unless you add WebDAV or an upload app
How soon a change shows upseconds with a file watcher running rclone; otherwise the next scheduled run (5 min for r2-sync)seconds with a file watcher (~4 s for s3-sync); otherwise the next scheduled runseconds with Syncthing or a watcher; the next run with rsync or rclone on a schedule
Pros✅ $0 downloads✅ HTTPS and DNS set up for you✅ No server to patch or watch✅ First 10 GB free✅ Part of AWS: IAM, versioning, lifecycle rules✅ CloudFront signed URLs can serve private files✅ No server to patch or watch✅ Browsable folder listing✅ Password with basic auth✅ Two-way and near real-time with Syncthing✅ Full control of headers and redirects
Cons❌ No folder listing❌ No password without Cloudflare Access❌ R2 needs a payment method to turn on❌ One way❌ ~$0.114/GB downloads❌ Website endpoint is HTTP only❌ Bucket name must equal the hostname❌ Turning off Block Public Access is easy to get wrong❌ Limited by the box's disk, shared with its databases❌ Down whenever the box is❌ You patch, monitor and back it up❌ ~$0.114/GB downloads

What was built: r2-sync

A small Windows tool around rclone, acp_test/tools/cloud-sync/r2-sync/ (alias r2-sync). The doc beside it, r2-sync.md, is the spec for rebuilding it elsewhere.

  • Mirror, one way: rclone sync D:\my-drive\r2-data r2:fa-r2-data. A local delete or rename reaches the bucket too.
  • Every 5 minutes from Task Scheduler, run through conhost.exe --headless so no window flashes up.
  • Cheap no-change runs: --update --use-server-modtime decides from one bucket listing, with no request per file.
  • Short cache: uploads get Cache-Control: public, max-age=300, so an edited file shows up within minutes.
  • Safety: if the source folder is completely empty (say, Google Drive hasn't mounted it yet), the run is skipped instead of wiping the bucket.
  • Ignored: desktop.ini, Thumbs.db, Office ~$ lock files, *.tmp, Google Docs shortcut files (.gdoc, .gsheet, …) and Google Drive's .tmp.drive* folders, from an rclone filter file.

The tool is tested against local folders. The bucket and custom domain wait on R2 being turned on for the Cloudflare account, and the r2 rclone remote isn't set up yet (r2-sync setup <key-id> <secret>).

What was built: s3-sync

The S3 twin of r2-sync, live at https://public.fishapple.com: acp_test/tools/cloud-sync/s3-sync/ (alias s3-sync), spec in s3-sync.md beside it.

  • Serving: S3 bucket public.fishapple.com (ap-southeast-2) with website hosting and a public-read policy, behind a proxied Cloudflare CNAME and a Flexible SSL configuration rule for that host only.
  • Near real time: a PowerShell FileSystemWatcher on D:\my-drive\s3-public runs rclone sync once nothing has changed for 3 seconds. A new, edited or deleted file shows up at the URL in about 4 seconds. Changes made during a sync queue up and trigger another.
  • Safety sync: a full sync every 5 minutes as well, in case Windows dropped an event. One with nothing to do costs a single LIST request.
  • Kept alive: a Task Scheduler task starts the watcher every 5 minutes, ignores repeats while it's running, and has no time limit. A named mutex stops a second copy. No admin rights needed.
  • Credentials: the rclone remote uses env_auth=true, so it reads the AWS CLI's ~/.aws/credentials. No key in rclone.conf.
  • Cache: Cache-Control: public, max-age=60, so browsers and Cloudflare re-check within a minute. no-cache would stop Cloudflare caching altogether, and every view would be a paid S3 download.
  • The same empty-folder guard and ignore list as r2-sync.

The watcher needs a real NTFS folder. Google Drive's mirror mode gives one (D:\my-drive). A streamed Drive letter (G:) doesn't fire change events reliably.

Disclaimer: These documents are personal notes. The information may be incomplete, out of date or wrong, so check it before you rely on it.