Status: CURRENT — HOMELAB / WORDPRESS SECURITY
Last reviewed: 31 October 2026
Applies to: WordPress behind Cloudflare, Cloudflare WAF Custom Rules, reverse proxies, VPN access and split DNS.This is how I keep the public side of my WordPress site public while making the useful attack surfaces — the login page, admin area and a bunch of commonly-probed sensitive files — effectively disappear from the public internet.
I self-host WordPress. That means I get all the fun of owning the server, controlling the stack and watching random bots from every corner of the planet repeatedly ask whether I accidentally left /.env lying around.
Spoiler: I did not. But they are very fucking optimistic.
For a normal public website, people need to read the site. They do not need to see the WordPress login page, the admin panel, XML-RPC or whatever secret-file path some scanner found in a five-year-old exploit list.
And for a homelab in particular, the answer is even simpler: if I need to administer WordPress remotely, I already have a VPN. I do not need to expose the admin interface to the entire internet just in case I suddenly feel the urge to edit a post from a servo at 2am.
The idea
The public site still goes through Cloudflare normally. Public pages, posts, images and comments continue to work. Cloudflare simply blocks requests for the parts I have no reason to expose publicly.
Public internet
|
v
Cloudflare
|
+---- normal WordPress pages ----------> ALLOW
|
+---- /wp-login.php -------------------> BLOCK
|
+---- /wp-admin/* ---------------------> BLOCK
| except admin-ajax.php
| and admin-post.php
|
+---- /xmlrpc.php ---------------------> BLOCK
|
+---- /.env, /.git/, /.ssh/, etc. ----> BLOCK
LAN / VPN
|
v
Split DNS / private route
|
v
Reverse proxy
|
v
WordPress
|
+---- /wp-login.php -------------------> WORKS
+---- /wp-admin/ ----------------------> WORKSThe important part is that the LAN/VPN path above is genuinely private. My internal DNS resolves the site to my internal reverse proxy instead of sending me back out through Cloudflare.
A VPN is not magic. If you connect to your VPN but your browser still resolves the site to Cloudflare and sends the request through Cloudflare, the WAF rule will still block you. That is Cloudflare doing exactly what you told it to do.
Use split DNS, an internal DNS override, a private hostname, or another private route so trusted LAN/VPN traffic reaches the origin without passing through the public Cloudflare rule.
Before doing this
Do not paste these rules into Cloudflare and immediately close every working WordPress session you have. That is a fantastic way to discover how good your recovery plan is.
- Make sure WordPress already works from your LAN or VPN.
- Make sure your internal or VPN DNS can resolve the WordPress hostname to the private reverse proxy/origin path.
- Keep an existing administrator session open while testing.
- Know how to disable a Cloudflare rule from the dashboard if you screw it up.
- If you use XML-RPC for a real service, confirm that before blocking it.
- Replace
richay.auwith your own hostname.
Cloudflare currently puts these under Security → Security rules → Create rule → Custom rules. Create the rule, use the expression editor, choose Block, then deploy it.
Rule 1 — Block WordPress login, XML-RPC and the admin area
This is the first rule I use on my WordPress hostname:
(http.host eq "richay.au" and (
http.request.uri.path eq "/wp-login.php"
or http.request.uri.path eq "/xmlrpc.php"
or (
starts_with(http.request.uri.path, "/wp-admin")
and http.request.uri.path ne "/wp-admin/admin-ajax.php"
and http.request.uri.path ne "/wp-admin/admin-post.php"
)
))Set the action to Block.
The result is deliberately boring: a public request to /wp-login.php, /xmlrpc.php or almost anything under /wp-admin never gets as far as WordPress. Cloudflare kills it at the edge.
That is much more appealing to me than rate-limiting the login page. If I have no legitimate reason to log in from the public internet, the correct number of public login attempts I want reaching WordPress is zero.
Why admin-ajax.php and admin-post.php are excluded
Those two exceptions are intentional.
WordPress uses wp-admin/admin-ajax.php for AJAX requests, including requests from the public-facing side of a site. Plugins and themes can legitimately depend on it even when the visitor is not logged in. WordPress itself warns that blindly protecting the entire /wp-admin/ directory can break AJAX functionality.
admin-post.php can also be used as a handler for front-end GET/POST actions, including unauthenticated actions registered by plugins.
So I block the admin area while leaving those specific handlers alone. Security is great. Randomly breaking your own site because the URL contains wp-admin is less great.
Will this block public comments?
No. Normal WordPress comment forms submit to /wp-comments-post.php, which this rule does not touch.
That means anonymous visitors can still read posts and submit comments normally. I still use WordPress spam controls for the comments themselves; the WAF rule is not trying to replace comment moderation.
What about XML-RPC?
WordPress still has an XML-RPC API and it can be used for remote publishing and other integrations. If you actually use something that depends on xmlrpc.php, do not blindly block it.
I do not need it for my setup, so from the public internet it can fuck right off.
Rule 2 — Block common secret-file and dotfile probes
The second rule is aimed at the constant scanner traffic looking for files that should never be publicly retrievable in the first place:
(
lower(http.request.uri.path) contains "/.env"
or lower(http.request.uri.path) contains "/.git/"
or lower(http.request.uri.path) contains "/.aws/"
or lower(http.request.uri.path) contains "/.ssh/"
or lower(http.request.uri.path) contains "/.htaccess"
or lower(http.request.uri.path) contains "/.htpasswd"
or lower(http.request.uri.path) contains "/.ds_store"
or lower(http.request.uri.path) eq "/info.php"
)Again, set the action to Block.
I use lower() so the comparison is case-insensitive. A scanner trying /.ENV instead of /.env does not deserve a participation trophy.
Unlike the WordPress-admin rule, this one is not restricted to richay.au in my configuration. That means it protects every proxied hostname in the Cloudflare zone. I am happy with that because none of my public services should be serving Git metadata, SSH keys, environment files or Apache password files anyway.
If you have an application that legitimately uses one of these paths, scope the rule to the relevant hostname instead of blindly deploying it zone-wide. Always protect the application you actually have, not the application some bloke on the internet had.
Optional: scope the sensitive-file rule to WordPress only
If you want the second rule to apply only to the WordPress hostname, wrap it with a host condition:
(http.host eq "example.com" and (
lower(http.request.uri.path) contains "/.env"
or lower(http.request.uri.path) contains "/.git/"
or lower(http.request.uri.path) contains "/.aws/"
or lower(http.request.uri.path) contains "/.ssh/"
or lower(http.request.uri.path) contains "/.htaccess"
or lower(http.request.uri.path) contains "/.htpasswd"
or lower(http.request.uri.path) contains "/.ds_store"
or lower(http.request.uri.path) eq "/info.php"
))What I deliberately did not block
The point is to remove unnecessary attack surface without turning the public WordPress site into a decorative 403 page.
/wp-comments-post.php— normal comment submission./wp-admin/admin-ajax.php— required by WordPress AJAX and potentially front-end plugins/themes./wp-admin/admin-post.php— can handle legitimate front-end POST/GET actions./wp-json/— WordPress REST API; many modern WordPress features and plugins use it./wp-content/— themes, plugins, uploads and other public assets./wp-includes/— WordPress core assets may be requested by public pages.
You can harden individual endpoints further if your own site does not use them, but I would rather block things because I understand why they are unnecessary than play URL whack-a-mole until the site stops working.
Testing from outside the network
Test the rules from a genuinely external connection: mobile data, another internet connection, or a machine that is not using your internal/VPN DNS.
curl -I https://richay.au/
curl -I https://richay.au/wp-login.php
curl -I https://richay.au/wp-admin/
curl -I https://richay.au/.env
curl -I https://richay.au/.git/config
curl -i https://richay.au/wp-admin/admin-ajax.phpThe exact headers depend on your Cloudflare configuration, but the important behaviour is:
- The normal homepage still loads.
/wp-login.phpis blocked by Cloudflare./wp-admin/is blocked by Cloudflare./.envand/.git/configare blocked by Cloudflare./wp-admin/admin-ajax.phpis not blocked by this custom rule. A plain request may simply return WordPress’s normal minimal response.
Testing from the LAN or VPN
Now connect through your trusted path and check where the hostname resolves:
nslookup richay.au
# Then test the login page
curl -I https://richay.au/wp-login.phpIn my design, the DNS lookup from the LAN/VPN resolves toward the private reverse-proxy path rather than Cloudflare. The login page therefore reaches WordPress normally and the Cloudflare WAF rule never sees the request.
If the VPN test still gives you the Cloudflare block page, check DNS first. You probably built a lovely VPN tunnel and then sent the browser straight back out to the public internet anyway. Networking: because apparently packets enjoy sightseeing.
Why this is particularly useful for a homelab
For a business with travelling staff, third-party administrators or multiple external management workflows, the access model might be more complicated.
For my homelab, it is not.
Need to read the site?
→ public internet is fine
Need to leave a comment?
→ public internet is fine
Need WordPress admin?
→ LAN or VPN
Need wp-login.php?
→ LAN or VPN
Random bot wants /.env?
→ lol noI already use private remote access for the rest of the homelab. Making WordPress administration use the same trusted path is not a burden; it is just removing an internet-facing door I was not actually using.
If you do occasionally need administration from somewhere without your VPN, I would rather temporarily use a deliberate access method — such as a private VPN connection or a properly configured identity-aware access layer — than permanently expose the WordPress login page because “maybe one day”.
This is defence in depth, not magic
Cloudflare blocking these requests is useful because the garbage traffic dies before it reaches WordPress or the origin web server. But it is still only one layer.
- Keep WordPress core, plugins and themes updated.
- Keep PHP and the underlying containers/host patched.
- Remove plugins and themes you do not use.
- Use strong authentication for the accounts that remain.
- Keep backups that are not writable by the public web application.
- Protect the origin itself; if someone can bypass Cloudflare and hit the origin directly, the Cloudflare rule obviously cannot save you.
- Keep origin-side protections in place as well. Edge blocking and server-side hardening complement each other.
I also run other security layers around my public services. The point of these Cloudflare rules is not to declare the site “unhackable” — anyone using that word should probably be escorted away from the keyboard — it is to cheaply remove traffic that has no legitimate reason to exist.
The final result
PUBLIC INTERNET
richay.au/ → allowed
richay.au/posts/... → allowed
richay.au/wp-comments-post.php → allowed
richay.au/wp-admin/admin-ajax.php → allowed
richay.au/wp-admin/admin-post.php → allowed
richay.au/wp-login.php → BLOCKED
richay.au/wp-admin/ → BLOCKED
richay.au/xmlrpc.php → BLOCKED
richay.au/.env → BLOCKED
richay.au/.git/config → BLOCKED
richay.au/.ssh/... → BLOCKED
LAN / VPN + SPLIT DNS
richay.au/wp-login.php → allowed
richay.au/wp-admin/ → allowedThat is exactly what I wanted: the website remains public, while the administrative surface is only available over a network path I already trust.
The bots can keep requesting wp-login.php all day if it makes them happy. WordPress never even gets invited to the conversation.
