Last active
August 29, 2015 14:21
-
-
Save muffl0n/1097615adaf6e65fb22b to your computer and use it in GitHub Desktop.
Apache 2.4 File-/Location-Directive glitch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<VirtualHost *:80> | |
ServerName test_file | |
DocumentRoot /tmp/test/htdocs | |
<Location "/"> | |
Require all granted | |
</Location> | |
<Files "test.html"> | |
AuthType Basic | |
AuthName "Test" | |
AuthUserFile /tmp/test/htpasswd | |
Require user test | |
</Files> | |
</VirtualHost> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<VirtualHost *:80> | |
ServerName test_location | |
DocumentRoot /tmp/test/htdocs | |
<Location "/"> | |
Require all granted | |
</Location> | |
<Location "/test.html"> | |
AuthType Basic | |
AuthName "Test" | |
AuthUserFile /tmp/test/htpasswd | |
Require user test | |
</Location> | |
</VirtualHost> |
According to http://httpd.apache.org/docs/2.4/sections.html#merging Location is evaluated after File and therefore overrides <Files "test.html">
. So if I use
<Directory "/tmp/test/htdocs">
Require all granted
</Directory>
instead of
<Location "/">
Require all granted
</Location>
everything works as expected.
<VirtualHost *:80>
ServerName test_directory
DocumentRoot /tmp/test/htdocs
<Directory "/tmp/test/htdocs">
Require all granted
</Directory>
<Files "test.html">
AuthType Basic
AuthName "Test"
AuthUserFile /tmp/test/htpasswd
Require user test
</Files>
</VirtualHost>
Result:
$ http --headers 127.0.0.1/test2.html Host:test_directory | head -1
HTTP/1.1 401 Unauthorized
Surprisingly according to http://httpd.apache.org/docs/2.2/sections.html#merging this behaviour didn't change from 2.2 to 2.4. But this clearly behaves different after upgrading to 2.4. Maybe there was a bug in 2.2?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems that the
<File>
-Directive does not override what's defined with<Location "/">
:Expected:
Actual: