Apache has a safety check for rewrite rules that I’d never heard of until it blocked every certificate renewal on one of my boxes. It has a log code, AH00670, and it’s perfectly happy to say nothing at all in the one place you’re looking.
The setup is a small bash tool that generates Apache vhosts and gets Let’s Encrypt certificates for WordPress sites, using lego over HTTP-01. For each domain it writes a port 80 vhost that does two things. It 301-redirects everything to HTTPS, and it carves out /.well-known/acme-challenge/ so the validation request isn’t redirected away from the token lego just wrote there.
That carve-out is a <Directory> block. I’d written it the cautious way, on the principle that a directory holding nothing but challenge tokens should be locked down as far as it’ll go:
<Directory "/var/www/example/.well-known/acme-challenge">
Options None
AllowOverride None
Require all granted
</Directory>
It looked tidy. Then renewals started failing.
What it looked like from outside
Let’s Encrypt reported the validation as failed with a 403. Not a 404, which would have meant the token wasn’t where it should be. A 403 on a file I could see sitting on disk, readable by the web server, in a directory with Require all granted.
I did the usual things. Permissions on the token, permissions up the path. Whether something upstream was blocking port 80. Whether a different vhost was answering. All fine, and all a bit embarrassing in hindsight, because the access log had the 403 and the Apache error log had the actual reason sitting two lines away:
AH00670: Options FollowSymLinks and SymLinksIfOwnerMatch are both off, so the RewriteRule directive is also forbidden due to its similar ability to circumvent directory restrictions
The cause
The vhost has a RewriteRule for the HTTP-to-HTTPS redirect, with a condition that skips it for the challenge path. Rewrite rules defined in the parent vhost are inherited into the <Directory> block. And mod_rewrite will not run its rules in a context where FollowSymLinks or SymLinksIfOwnerMatch is on, because a rewrite can map a request to a filesystem path and Apache treats that as a way round the symlink restrictions.
Options None turns both off. So the inherited rule was refused outright, the request came back 403, and the carve-out that existed purely to let the challenge through was the thing blocking it.
The message lives in the Apache error log, not in anything lego prints. Lego says the server returned 403, which is accurate and not much use.
The fix
One word, plus a comment so I don’t tidy it back later:
<Directory "/var/www/example/.well-known/acme-challenge">
# FollowSymLinks, not "Options None". Rewrite rules inherited from the
# parent vhost are refused (AH00670) when both symlink options are off,
# and every validation then returns 403.
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Is that a loosening? Technically. In this case the directory contains short-lived tokens and nothing else, no symlinks to protect, and AllowOverride None and Require all granted are unchanged. I looked at it for a while and decided I could live with it. Your directory might not be that boring.
While I was in there
The same vhost generator has two sibling traps that only matter if you’re doing this on a Bitnami-style stack. I’ll just list them, since they bit in the same week of fiddling.
If an Alias /.well-known/acme-challenge/ directive exists anywhere (left over from an earlier manual setup, say), Apache processes it before the rewrite rules WordPress would use to serve the file, and it points at a directory that has none of your tokens. The tool now removes a stale one on install.
And a *:80 vhost isn’t the same thing as a _default_:80 one. They’re separate groups, and the *:80 one wins. Add a generated port 80 block for one domain and it quietly takes over traffic that the old catch-all was handling for everything else. Which is a fun thing to discover after the fact.
What I’d take from it
If an ACME challenge returns 403 and the file is there and readable, stop checking the file. Go to the error log and read the actual line. And be a little suspicious of Options None anywhere a rewrite might be inherited.
