The Site Folder Also Holds Private Files

This site is a folder of static HTML that nginx serves from /var/www/codertronix.com. The same folder also holds a lot of things that should never be public: the nginx config, a Go service that runs the comments, Python scripts that compress files and draw images, a CLAUDE.md file of notes for my coding assistant, the .git directory, and a few audit folders full of CSV and Markdown reports. When I wrote this, git ls-files listed 999 tracked files, and about 900 of them belonged on the server.

The easy deploy is rsync -av ./ /var/www/codertronix.com/, and it copies everything. After that, nginx is the only thing standing between a visitor and /.git/config, my scripts or a stray key file. One wrong location block and they can be downloaded. I would rather those files never reach the server.

So the deploy uses an allowlist. A filter file, nginx/deploy.rsync-filter, names what may go to the webroot, and everything else stays behind. This post goes through that file rule by rule. It shows what rsync really does with it and with three broken versions of it, and how I run it from a Windows machine that has no rsync. Every screenshot below is real output: from a copy of the repo with fake private files planted in it, from Git Bash on my machine, from read-only commands on the server, or from curl against the live site.

Why an Allowlist and Not a Denylist

A denylist says "copy everything except these". You write --exclude=.git --exclude='*.pem' --exclude=scripts/, and it works on the day you write it. Later you add a notes/ folder, a .env for some new tool or a backup.sql dump, and the denylist ships it because nobody told it not to. A denylist fails open: every new kind of file is public until someone remembers to block it.

An allowlist says "copy these and nothing else". A new file stays on my machine until I add a rule for it. When the allowlist is wrong, it fails closed. A page I forgot to allow is missing from the server, and a missing page turns up as a 404 the first time anyone checks. A leaked file turns up nowhere, at least not for me. Given the choice, I will debug the 404.

The price is upkeep. Every new public path at the top of the site needs a line in the filter. The two IndexNow key files each have their own rule. The filter also lists search-engine verification files (google*.html, BingSiteAuth.xml, yandex_*.html) that do not exist yet, so adding one later will not end in a 404 that the verification check fails on. For a site whose public part is six folders and about a dozen root files, that is a short list to keep up to date.

The Filter File, Rule by Rule

Here is the whole file without its header comment:

nginx/deploy.rsync-filter
# ---- 1. Never ship, at any depth (checked before the allowlist) ----
- CLAUDE.md
- CLAUDE.md.br
- CLAUDE.md.gz
- *.pem
- *.key
- *.env
- *.py
- *.pyc
- *.sh
- *.go
- *.service
- __pycache__/

# ---- 2. Dot paths: only /.well-known/ is public ----
+ /.well-known/***
- .*

# ---- 3. Public directories ----
+ /css/***
+ /fonts/***
+ /images/***
+ /js/***
+ /pages/***
+ /posts/***

# ---- 4. Public root files (the trailing * also picks up .br / .gz siblings) ----
+ /index.html*
+ /404.html*
+ /50x.html*
+ /favicon.svg*
+ /manifest.json*
+ /robots.txt*
+ /ads.txt*
+ /feed.xml*
+ /sitemap*.xml*
# IndexNow / search-engine key files (32-hex name, served by nginx allowlist)
+ /94bedfcb5cb0430f88da93fb0d1ae047.txt*
+ /dbab63327fb246578f08e2f47633576e.txt*
# Search-engine verification files, if added later (see never-block.conf)
+ /google*.html*
+ /BingSiteAuth.xml*
+ /yandex_*.html*

# ---- 5. Everything else stays local ----
- *

This is the command that uses it, run from the top of the folder being deployed:

terminal
sudo rsync -av --delete --delete-excluded \
    --filter='merge nginx/deploy.rsync-filter' \
    ./ /var/www/codertronix.com/

Four rules from the rsync man page explain the whole file.

The first matching rule wins. In the man page's words, "the first rule that matches is the one that takes effect." rsync checks each path against the rules from the top down and stops at the first match. That explains the order of the file. The hard excludes come first, so a CLAUDE.md inside posts/ hits - CLAUDE.md before it can reach + /posts/***. The catch-all - * comes last, so it only sees paths that no earlier rule claimed.

A leading slash anchors a pattern: one that starts with / is matched from the root of the transfer. + /posts/*** means the posts folder at the top of the site, and not some folder called posts further down. A pattern with no slash in it, like *.pem or CLAUDE.md, is matched only against the last part of the path, so it applies at any depth. That is what the hard excludes need, because a key file is no safer for sitting inside images/.

A trailing *** means the folder and everything in it. The man page calls a trailing *** "a shorthand that allows you to match a directory and all its contents using a single rule." Without it, + /posts/ matches only the directory itself, and the files inside fall through to - *. You will see that happen further down.

The trailing * on root files picks up the compressed copies. Every public text file on this site has a .br and a .gz sibling for nginx to serve. + /index.html* matches index.html, index.html.br and index.html.gz in one rule.

The merge in --filter='merge nginx/deploy.rsync-filter' reads rules from a file. The man page says those rules are "incorporated into the filter list in the place of the" merge rule, so the file behaves as if each line had been typed on the command line in that order. Keeping the rules in a file means they live in git next to the site and get reviewed like any other change.

The dot-path section is worth a second look. - .* blocks every name that starts with a dot: .git, .claude, .vscode, .env, .editorconfig. But /.well-known/ has to be public, because it holds security.txt. So + /.well-known/*** sits right above - .*. Swap those two lines and security.txt stops deploying without any error.

Testing It Against Planted Private Files

Reading a filter file tells you what it should do. To see what it actually does, I copied every tracked file of the repo into a scratch folder in WSL (Ubuntu, rsync 3.4.1). Then I planted fakes of the things I worry about. In the commands below, $W is that scratch folder.

terminal
cd "$W/site"
mkdir -p notes .git
echo "fake server notes, nothing real" > notes/server.txt
echo "-----BEGIN DUMMY KEY----- not-a-real-key -----END DUMMY KEY-----" > deploy.pem
echo "COMMENTS_ADMIN_TOKEN=test-token-123" > .env
echo "print('hello')" > scripts/x.py
echo "ref: refs/heads/main" > .git/HEAD
echo "TODO" > draft-notes.md

Next comes a dry run into an empty folder. -n (--dry-run) makes no changes. -i (--itemize-changes) prints one line per item, starting with a short code: >f+++++++++ for a new file that would be sent, cd+++++++++ for a new directory, and *deleting for anything that would be removed. I save that plan to a file so I can grep it as often as I like:

terminal
rsync -n -ai --delete --delete-excluded \
  --filter='merge nginx/deploy.rsync-filter' ./ "$W/empty/" > "$W/dry-empty.txt"
wc -l < "$W/dry-empty.txt"
grep -cE '^>f' "$W/dry-empty.txt"
grep -E 'pem|\.env|server\.txt|\.py$|\.git/|CLAUDE|notes|draft-notes|nginx/|services/|\.claude|\.vscode|\.sh$' \
  "$W/dry-empty.txt" || echo "(no private paths)"
grep -E '\.well-known' "$W/dry-empty.txt"
Terminal: rsync dry run into an empty folder lists 914 lines, 904 of them files; grep for private paths prints (no private paths); grep for .well-known shows the directory and security.txt with .br and .gz.
Real output. 904 files would be sent. None of the planted fakes (deploy.pem, .env, notes/server.txt, scripts/x.py, .git/) is in the plan, and /.well-known/ is the only dot path.

The plan sends 904 files, and none of the planted fakes is among them. Nothing comes from nginx/, services/ or scripts/ either, and none of the CLAUDE.md files. The .well-known lines show the one dotfile exception working. The other ten lines of the 914 are directories. The 904 also checks out against the server: a read-only find /var/www/codertronix.com -type f | wc -l on the live webroot printed 904 too.

--delete Versus --delete-excluded

Sending the right files is half of a deploy. The other half is removing files that should not be there any more. --delete removes files from the destination that are no longer in the source. When I change the CSS or JS, the file gets a new hashed name (main.7ea636b2.js became main.f66efe8e.js). Without --delete, the old copies would pile up in the webroot.

--delete has one exception that matters a lot here. From the man page: "Files that are excluded from the transfer are also excluded from being deleted unless you use the --delete-excluded option." By default an exclude rule does two jobs. It hides a file on the sending side, and it protects the same path on the receiving side. So if a careless deploy once copied deploy.pem or .git/ into the webroot, --delete alone will never remove them, because my filter excludes them. --delete-excluded makes the excludes apply to the sender only. The leftovers then count as extra files and get deleted.

To see the difference, I built a stale webroot: a correct deploy, plus the three old hashed JS files, a fake key, a notes folder and a .git directory, as if an earlier deploy had left them behind. Then I ran two dry runs against it:

terminal
F='merge nginx/deploy.rsync-filter'
rsync -n -ai --delete --delete-excluded --filter="$F" ./ "$W/stale/" | tee "$W/A.txt" | grep -E '^\*deleting'
echo "total lines: $(wc -l < $W/A.txt)"
rsync -n -ai --delete --filter="$F" ./ "$W/stale/" | tee "$W/B.txt" | grep -E '^\*deleting'
echo "total lines: $(wc -l < $W/B.txt)"
Terminal: the --delete-excluded dry run lists eight deletions including notes/server.txt, .git/HEAD, deploy.pem and three main.7ea636b2.js files; the --delete-only run lists just the three JS files.
Real output. With --delete-excluded the planted key, notes and .git go along with the old JS. With --delete alone, the excluded leftovers are protected and stay.

With both flags, eight items go: the three stale JS files and everything I planted. With --delete alone, only the three JS files go, because they are no longer in the source. The key, the notes and .git match exclude rules, so they are protected and stay in the webroot. Nginx happens to refuse all three by name, but I do not want the deploy to depend on that.

Table of four leftovers in a stale webroot. The old main.7ea636b2.js files are deleted by --delete and by --delete-excluded. deploy.pem, notes/server.txt and .git/HEAD are deleted only when --delete-excluded is added.
What each flag removes from a stale webroot. Dry run: 3 deletions with --delete, 8 with --delete-excluded.

--delete-excluded has a cost of its own. It removes everything in the webroot that the filter does not allow, including files someone put there on purpose. On this server the two things that are not part of the deploy, the shared ads.txt and certbot's challenge files, live in /var/www/shared and /var/www/letsencrypt, next to the webroot and not inside it. If uploads, a cache folder or a CMS write into the same directory you deploy to, this flag will delete their files.

Three Filter Mistakes and What They Do

None of these mistakes produces a warning. Each one leaves a valid filter file, and rsync does exactly what the file says. I made each one on purpose in a copy of the filter and ran it against the same planted repo.

An allow rule added after - *

Say you add a new public folder and append its rule to the end of the file, under the catch-all. To test this, I moved + /posts/*** to the bottom:

terminal
grep -v '^+ /posts/\*\*\*$' nginx/deploy.rsync-filter > "$W/bad/late-allow.filter"
echo '+ /posts/***' >> "$W/bad/late-allow.filter"
tail -3 "$W/bad/late-allow.filter"
rm -rf "$W/t1"; mkdir "$W/t1"
rsync -n -ai --filter="merge $W/bad/late-allow.filter" ./ "$W/t1/" > "$W/m1.txt"
echo "posts lines: $(grep -c ' posts/' "$W/m1.txt")  total: $(wc -l < "$W/m1.txt")"
Terminal: a filter with + /posts/*** after - * produces a dry run with 0 lines under posts/ out of 802.
Real output. The allow rule under - * is never reached: the plan has nothing from posts/.

The plan has no lines under posts/ at all. Every path in that folder matches - * first, so the rule below it is never read. The deploy would send the rest of the site, 802 lines of it, without a single article. A real run with --delete-excluded would also delete the articles already in the webroot, since they are now excluded and that flag removes excluded files. This is an allowlist failing closed. It is loud and obvious, and it would still take the site's content down until fixed. A dry run catches it first.

A folder rule without ***

terminal
sed 's#^+ /posts/\*\*\*$#+ /posts/#' nginx/deploy.rsync-filter > "$W/bad/no-stars.filter"
grep -n '^+ /posts' "$W/bad/no-stars.filter"
rm -rf "$W/t2"; mkdir "$W/t2"
rsync -n -ai --filter="merge $W/bad/no-stars.filter" ./ "$W/t2/" > "$W/m2.txt"
grep ' posts' "$W/m2.txt" | head -5; echo "posts lines: $(grep -c ' posts' "$W/m2.txt")"
Terminal: with + /posts/ instead of + /posts/***, the dry run shows only cd+++++++++ posts/ and one posts line.
Real output. + /posts/ matches only the directory, so rsync creates an empty posts/ folder and sends none of its files.

rsync creates an empty posts/ directory and sends nothing into it. + /posts/ matches the directory, and then each file inside is checked on its own. posts/linux-shell-scripting.html matches nothing until - *. The man page's own examples include the parent directory as a separate rule (+ foo/, then + foo/bar.c, then - *) for this exact reason. *** covers both in one line.

Hard excludes moved below the allowlist

This one leaks, and it is the mistake I worry about most, because the file still looks right when you read it. Every exclude is there. They are just in the wrong place. I moved section 1 of the file to sit right above - *, and planted two more fakes inside public folders, posts/leak.pem and images/resize.py. From here on, F holds the full path to the real filter file, and t3 is another empty folder:

terminal
echo dummy > posts/leak.pem; echo "print(1)" > images/resize.py
rsync -n -ai --filter="merge $W/bad/late-excludes.filter" ./ "$W/t3/" | grep -E 'leak\.pem|resize\.py'
rsync -n -ai --filter="merge $F" ./ "$W/t3/" | grep -E 'leak\.pem|resize\.py' || echo "(not listed)"
rm posts/leak.pem images/resize.py
rsync -n -ai --filter="merge $W/bad/late-excludes.filter" ./ "$W/t3/" | grep CLAUDE || echo none
rsync -n -ai --filter="merge $F" ./ "$W/t3/" | grep CLAUDE || echo "(not listed)"
Terminal: with the hard excludes moved below the allowlist, the dry run sends images/resize.py, posts/leak.pem and CLAUDE.md from css, fonts, pages and posts; the real filter prints (not listed) both times.
Real output. Same rules, wrong order: the allow rules claim the key, the script and four CLAUDE.md files before the excludes see them. The real filter lists none of them.

With the excludes moved down, the key and the script go out with everything else. So do four CLAUDE.md files that git tracks inside css/, fonts/, pages/ and posts/. + /posts/*** claims posts/leak.pem before - *.pem ever sees it. With the real filter, none of them is listed. The order of the sections is what makes the file safe: excludes first, allows second, catch-all last.

Three broken filter files side by side with what the dry run showed. An allow rule after - * sends zero files under posts. A rule without *** creates only the empty posts folder. Excludes below the allowlist let posts/leak.pem, images/resize.py and four CLAUDE.md files through.
The three mistakes, with the dry-run result for each. Only the third one leaks, and it reads like a correct file.

Deploying From Windows, Which Has No rsync

The machine I deploy from runs Windows, and it has no rsync. So I split the deploy in two: I package the files on Windows, and the filtering happens on the server, where rsync is already installed.

The package is built from git ls-files and never from the folder on disk. Only tracked files can ship that way. Whatever is lying around untracked or ignored (a cache, an editor's settings, a scratch export) is never even listed. On my machine right now, git status --short --ignored shows .claude/settings.local.json, .ruff_cache/ and scripts/__pycache__/, among others. A plain tar of the folder would pick all of them up.

A short regex file narrows the tracked list to the public paths, and the filter file is added to the list so the server has it to merge. The regex is a rough first cut, and the filter on the server is the one that decides. You can see that in the output below: the regex lets the four tracked CLAUDE.md files into the package, and the filter's first section drops them on the server.

Git Bash on Windows
command -v rsync || echo "no rsync here"
cat "$OUT/public.regex"
git ls-files | wc -l
git ls-files | grep -Ef "$OUT/public.regex" > "$OUT/files.txt"
echo nginx/deploy.rsync-filter >> "$OUT/files.txt"
wc -l < "$OUT/files.txt"
grep CLAUDE "$OUT/files.txt"
tar -czf "$OUT/site.tgz" -T "$OUT/files.txt"
tar -tzf "$OUT/site.tgz" | wc -l
Git Bash: no rsync on the machine; the public regex; git ls-files lists 999 files, the filtered list 909, including four CLAUDE.md files; the tarball holds 909 entries.
Real output. Packaging on Windows: 999 tracked files narrowed to 909. The four CLAUDE.md files get into the package and are dropped by the filter on the server.

When I rebuilt the list for this post it came to 909 entries. The package from the deploy described below held 910, so the exact count depends on the commit. The filter file itself never reaches the webroot. Nothing allows nginx/, so it falls to - *, and the dry run earlier did not list it.

On the server, the package goes into a fresh staging folder, and rsync runs from there with the same filter file. The folder names below are examples:

on the server
# from Windows
scp site.tgz user@server:/tmp/site.tgz

# on the server: a new, empty staging folder every time
rm -rf ~/deploy-staging && mkdir ~/deploy-staging
tar -xzf /tmp/site.tgz -C ~/deploy-staging
cd ~/deploy-staging
sudo rsync -n -ai --delete --delete-excluded \
    --filter='merge nginx/deploy.rsync-filter' \
    ./ /var/www/codertronix.com/ | grep '^\*deleting'

The staging folder has to start empty because rsync treats it as the full truth about the site. If I extracted a new package over an old staging folder, a post I had deleted from git would still be sitting there. rsync would keep sending it, and --delete would never remove it from the webroot.

Flow from the repo folder with 999 tracked files, through git ls-files and a public regex, to site.tgz copied by scp, extracted into a fresh staging folder on the server, then rsync with the filter into the webroot. Three notes: package, filter on the server, guard rails.
The Windows half only chooses tracked public files. The rsync filter on the server makes the final decision.

The Dangerous Part: --delete and the Wrong Path

The man page is blunt about --delete: "This option can be dangerous if used incorrectly!" It also says what to do about it: "It is a very good idea to first try a run using the --dry-run (-n) option to see what files are going to be deleted." Two paths in the command decide what gets deleted, the source and the target, and a slip in either one is easy to make.

The source needs its trailing slash

A trailing slash on the source means "the contents of this folder". Without it, rsync copies the folder itself, by name, into the target. With this filter, the missing slash has a second effect. The root of the transfer moves up one level, so the first path rsync checks is site. No anchored allow rule matches it, - * does, and the man page says that "when a directory is excluded, all its contents and sub-contents are also excluded." I ran both forms:

terminal
rm -rf "$W/t4"; mkdir "$W/t4"
rsync -n -ai --filter="merge $F" ./ "$W/t4/" | sed -n '1,3p'
cd "$W"; rsync -n -ai --filter="merge $F" site "$W/t4/" | sed -n '1,3p'
echo "count: $(rsync -n -ai --filter="merge $F" site "$W/t4/" | wc -l)"
Terminal: rsync with ./ lists ./, 404.html and 404.html.br; the same command with source site prints nothing and count: 0.
Real output. With ./ the site's files are sent. With site (no slash) the top folder itself is checked first, matches - *, and nothing is sent.

With ./ the plan starts with the site's files. With site it is empty. Here the allowlist made the mistake harmless, but a plain rsync -av site /var/www/codertronix.com/ without a filter would have created /var/www/codertronix.com/site/, and every URL would have moved under /site/.

A target one level too high

This one can take the whole site down. Type /var/www/ where you meant /var/www/codertronix.com/, and --delete-excluded takes everything in /var/www that the filter does not allow as something to delete. On the server, /var/www holds codertronix.com, html, letsencrypt and shared. I built a similar layout in the scratch folder, with a deployed site, a shared ads.txt and a fake certbot challenge file, and ran the dry run against the parent:

terminal
rsync -n -ai --delete --delete-excluded --filter="merge $F" ./ "$W/var/www/" > "$W/wrong.txt"
grep '^\*deleting' "$W/wrong.txt" | grep -vE 'codertronix.com/.+/' | head -20
echo "deletions: $(grep -c '^\*deleting' "$W/wrong.txt")   new files: $(grep -c '^>f' "$W/wrong.txt")"
Terminal: a dry run with target var/www lists deletions of shared/ads.txt, letsencrypt/.well-known/acme-challenge and codertronix.com files, ending with deletions: 920 new files: 904.
Real output. Pointing the same command at /var/www/ in a scratch copy: the shared ads.txt, the certbot challenge folder and the whole deployed site would be deleted.

That one command would delete 920 items: the whole deployed site, the shared ads.txt and the certificate challenge folder. It would then scatter 904 files straight into /var/www. The second grep hides files in subfolders of the site to keep the output short. The dry run shows all of it before anything is touched, which is why I do not deploy without it.

Two directory trees. With the target /var/www/codertronix.com/ only the site folder is synced and shared/ads.txt and letsencrypt are untouched. With the target /var/www/ the site folder, shared/ads.txt and letsencrypt are all deleted and the site files are created directly in /var/www. The dry run counted 920 deletions and 904 new files.
The same command with the target one level too high. Every folder next to the site counts as excluded, and --delete-excluded deletes it.

A dry run only helps if someone reads it. A few lines of shell can also refuse the obvious mistakes before rsync starts. I tested this guard for the post. It checks that the target ends in the site folder with its trailing slash, and that it runs from a folder that has an index.html and the filter file:

guard.sh
#!/usr/bin/env bash
set -euo pipefail
DEST=${1:-/var/www/codertronix.com/}
case "$DEST" in
  */codertronix.com/) ;;
  *) echo "refusing: $DEST is not the site folder" >&2; exit 1 ;;
esac
if [ ! -f index.html ] || [ ! -f nginx/deploy.rsync-filter ]; then
  echo "refusing: run this from the staging folder" >&2; exit 1
fi
echo "ok: $PWD -> $DEST"
terminal
bash ../guard.sh; echo "exit=$?"
touch index.html nginx/deploy.rsync-filter
bash ../guard.sh /var/www/; echo "exit=$?"
bash ../guard.sh /var/www/codertronix.com; echo "exit=$?"
bash ../guard.sh | sed "s#$PWD#STAGE#"; echo "exit=$?"
Terminal: guard.sh refuses to run outside a staging folder, refuses /var/www/ and /var/www/codertronix.com without a slash, and prints ok for /var/www/codertronix.com/.
Real output. The guard refuses the wrong folder, the parent target and the target without its trailing slash, and allows only the exact site folder.

It is deliberately strict. Even /var/www/codertronix.com without the trailing slash is refused, because I would rather retype the path than think about which form rsync wants. set -euo pipefail makes the script stop at the first failure. The shell scripting guide explains what each of those flags does.

Backups and Rollback

Before syncing, I tar the whole webroot into /var/backups. It is one command, along these lines:

on the server
sudo tar -czf "/var/backups/codertronix-webroot-$(date +%Y%m%d-%H%M%S).tgz" \
    -C /var/www codertronix.com

This is what is in /var/backups now, from read-only commands on the server:

server, read-only
ls -l /var/backups | grep codertronix-webroot
find /var/www/codertronix.com -type f | wc -l
ls /var/www/codertronix.com/js | grep main
tar -tzf /var/backups/codertronix-webroot-20261117-173403.tgz | grep -c main.7ea636b2
Server terminal: two codertronix-webroot tgz backups of about 43.7 MB in /var/backups, 904 files in the webroot, main.f66efe8e.js with .br and .gz, and 3 main.7ea636b2 entries in the older backup.
Real output. Two webroot backups from 17 November. The live webroot has 904 files, and the earlier backup still holds the three old main.7ea636b2.js files.

The listing shows the two webroot backups from 17 November, just under 44 MB each. On 17 November the live webroot had 904 files, and its JS was main.f66efe8e.js. The earlier backup still holds the three main.7ea636b2.js files that the deploy removed, so going back to it brings the old JS back too.

Extracting a backup straight over the webroot would not be a clean rollback. Files that the bad deploy added would stay. The cleaner way is to unpack the backup somewhere else and sync it back with --delete:

on the server
sudo rm -rf /tmp/rollback && sudo mkdir /tmp/rollback
sudo tar -xzf /var/backups/codertronix-webroot-20261117-173403.tgz -C /tmp/rollback
sudo rsync -n -ai --delete /tmp/rollback/codertronix.com/ /var/www/codertronix.com/ | grep '^\*deleting'
# read the plan, then run it again without -n
sudo nginx -t && sudo systemctl reload nginx

No filter is needed here, because the backup holds only what was public when it was taken. The same dry-run habit still applies. At just under 44 MB each the backups pile up, so old ones need deleting now and then.

What the Real Deploy Looked Like

On 17 November I deployed this way. The package held 910 files. I backed up the webroot first, then ran the rsync as a dry run with -n and -i and grepped for *deleting lines:

on the server
sudo rsync -n -ai --delete --delete-excluded \
    --filter='merge nginx/deploy.rsync-filter' \
    ./ /var/www/codertronix.com/ | grep '^\*deleting'
# exactly what I expected to go? then the real run, without -n
sudo rsync -av --delete --delete-excluded \
    --filter='merge nginx/deploy.rsync-filter' \
    ./ /var/www/codertronix.com/
sudo nginx -t && sudo systemctl reload nginx

The dry run listed exactly three deletions: the old js/main.7ea636b2.js and its .br and .gz siblings, which the new hashed file had replaced. It also showed 163 changed files. Those three deletions were the whole list, so no old key, notes file or stray folder was waiting in the webroot to be removed. Then I ran it for real, ran nginx -t, reloaded nginx and checked the live site with curl.

A later full deploy the same day showed 0 deletions. That is the normal result when nothing has been renamed or removed since the last sync. An unexpected *deleting line on a quiet day is the thing to stop and read.

Nginx Refuses the Same Files

The filter keeps private files off the disk. The nginx server block refuses them anyway, in case one gets there some other way, such as a hand-typed rsync -av or a file left over from before the allowlist existed. These are the deny rules from nginx/sites-available/codertronix.com.conf:

nginx
# Tooling / source directories: never part of the public site.
location ^~ /nginx/      { access_log off; log_not_found off; return 404; }
location ^~ /services/   { access_log off; log_not_found off; return 404; }
location ^~ /scripts/    { access_log off; log_not_found off; return 404; }
location ^~ /components/ { access_log off; log_not_found off; return 404; }

# Hidden files / dotdirs at any depth, except /.well-known/
location ~ /\.(?!well-known/) {
    access_log off;
    log_not_found off;
    return 404;
}

# Keys, secrets, source code, docs, backups, and service units.
location ~* \.(?:pem|key|crt|csr|p12|pfx|jks|env|ini|toml|ya?ml|lock|md|py|pyc|go|mod|sum|sh|service|conf|bak|backup|swp|tmp|orig|old|log|sql)(?:\.(?:br|gz))?$ {
    access_log off;
    log_not_found off;
    return 404;
}

Order matters in nginx too, for a different reason. The nginx docs say that regular expression locations "are checked, in the order of their appearance in the configuration file," and that the search "terminates on the first match". So these deny rules sit above the static-file caching rules. If they came after a caching rule that matches by file type, a request for /.claude/settings.json could match the caching rule first and never reach the dotfile deny. The ^~ prefix locations work differently. When the longest matching prefix has ^~, nginx skips the regular expressions completely, so /scripts/ returns 404 whatever the file's extension. For the rest of this server's setup, see deploying this site to EC2 with nginx.

The check from outside covers both layers at once. Public URLs should answer 200, and private ones should answer 404, whether the file exists on disk or not:

terminal
for p in / /.well-known/security.txt /CLAUDE.md /posts/CLAUDE.md /.git/HEAD /.env \
         /deploy.pem /nginx/deploy.rsync-filter /scripts/compress.py \
         /services/comments/main.go /notes/server.txt; do
  printf '%-28s ' "$p"
  curl -s -o /dev/null -w '%{http_code}\n' "https://codertronix.com$p"
done
Terminal: curl loop against codertronix.com; / and /.well-known/security.txt return 200; CLAUDE.md, .git/HEAD, .env, deploy.pem, nginx, scripts, services and notes paths return 404.
Real output. From outside: the two public URLs answer 200, and every private path answers 404.

From outside, you cannot tell which layer produced a 404. /posts/CLAUDE.md is not in the webroot because the filter dropped it, and nginx would refuse it anyway because it ends in .md. With two layers, either one can fail and the file still stays private.

The Checklist I Deploy With

The filter file is 62 lines, comments included. With it, a key or a notes file can sit in the repo folder without ever reaching the server. My rule is still that keys and server notes do not belong in the repo folder at all. The allowlist is for the day that rule gets broken.

AS

Anurag Sinha

Founder & Lead Developer

Anurag is a full stack developer and self-taught programmer from India with over five years of experience building web applications, APIs, and cloud-native systems. He researches, writes and reviews every tutorial on Codertronix, and updates them when the tools change.