I got a virtualhost, which has some access restrictions configured like this:
<Location "/">
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /var/www/domain/htdocs/.htpasswd
Require valid-user
</Location>
In addition to that, I have the following conf
-file:
Alias /.well-known/acme-challenge/ "/var/www/letsencrypt/"
<Location /.well-known/acme-challenge/>
# Security Options
Options None
AllowOverride None
ForceType text/plain
RedirectMatch 404 "^(?!/\.well-known/acme-challenge/[\w-]{43}$)"
# Do not redirect to https or perform other rewrites
RewriteEngine off
</Location>
I need /.well-known/acme-challenge/
to be accessible without auth.
I have already tried adding different variations of Require all granted
to my conf
-file, but to no avail.
How can I make /.well-known/acme-challenge/
accessible without authentication for all virtualhosts? (I do not want to modify any virtualhosts, this virtualhost is just an example).
There is no possibility to override the
<Location />
statement from your virtualhost-context in the server-context. From apache doc:The order of merging is (last merged group wins):
<Directory>
(except regular expressions) and .htaccess done simultaneously (with .htaccess, if allowed, overriding<Directory>
)<DirectoryMatch>
(and<Directory "~">
)<Files>
and<FilesMatch>
done simultaneously<Location>
and<LocationMatch>
done simultaneously<If>
Apart from
<Directory>
, each group is processed in the order that they appear in the configuration files.<VirtualHost>
is not allowed inside<If>
so<Location>
is the last merged.But
If you only serve the site in a https vhost (what would be reasonable, because of the authentication), you can do the following (without affecting your https vhost):
Apache v2.2
letsencrypt-well-known.conf
:Apache v2.4
letsencrypt-well-known.conf
:In Apache 2.4, you can add an
Require expr
statement to the first location block and evaluate the request URI, like so:or something along that line (syntax not actually tested). The strange
m#
syntax is an alternative form for regexes to be able to use/
in the string.expr
docs: https://httpd.apache.org/docs/2.4/expr.html