httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "PAN, JIN" <>
Subject RE: Question on multiple <Directory> sections merging
Date Tue, 03 Nov 2015 21:36:17 GMT
Hi again,

Sorry it's still an user issue, but I'm writing to this list to inform people that I have
been helped. Thanks Jacob!

I did not understand that the <Directory "/path">  requires its path input to have the
absolute path of DocumentRoot prefixed. The dir merge function from mod_dir and my own mod
were both correctly provided with pointers that point to nothing, as directory mappings were
not successful.

The corrected config should have been like this for the non working Case2 stated in my original

                <Directory /usr/local/apache2/htdocs/>
                <Directory /usr/local/apache2/htdocs/foo>
                                DirectoryIndex foo.html
                <Directory /usr/local/apache2/htdocs/foo/bar>


From: PAN, JIN
Sent: Tuesday, November 03, 2015 3:06 PM
Subject: Question on multiple <Directory> sections merging


Is there anyone familiar with the Apache <Directory> section merge that can explain
the merging behavior?

Posting this to dev, because this is not a usage issue. We are writing a custom module that
needs to have different context from multiple <Directory> sections merged, so that a
request made for "foo/bar" will have access to its top level <Directory> context, ie
"foo/" and "/" as well.

We observed the following merge behavior with <Directory>, and don't understand what's
going on...

-          The merge happens from "/" to "/dir1/dir2" if config line exists in "/", but NOT
from "/dir1" to "/dir1/dir2" if config line exists in "/dir1".

This is problematic if everything only works if we must specify something at the "/" level.

-          Order of the config lines as they appear in httpd.conf does not matter.

I'm demonstrating this using foo.html and the version 2.4 mod_dir rather than my mod, in order
to exclude any user coding issues. (So in other words, mod_dir's merge_dir_configs behaves
the same as my mod). Given the file location below, and as in Case 1 working config below,
the Directory "/" config defines foo.html,  and a request made for "foo/bar" properly displays
the "htdocs/foo/bar/foo.html" page demonstrating the config merge from "/" to "foo/bar". However,
if we move the same config line to the "/foo" section (as in Case2 below), then the merge
does not happen, and in this case, the same request for "foo/bar" displays the standard directory
listing, and not the foo.html page even though it exists in /foo/bar directory. Why?

I would like to point out that if all sections are changed to use <Location> instead,
then the foo.html is displayed in both cases. But just having <Location> working the
way we want is insufficient as we cannot tell our users to only use <Location>.

We are going by the Apache 2.4 documentation (link included below) to expect the config lines
illustrated in both cases to merge the directory contexts. Any insights to the merging sequence
will be greatly appreciated!

Thank you!

                % ls /usr/local/apache2/htdocs
                % ls /usr/local/apache2/htdocs/foo
                % ls /usr/local/apache2/htdocs/foo/bar

Case 1: Working Config:
                <Directory />
                                DirectoryIndex foo.html
                <Directory /foo>
                <Directory /foo/bar>

Case 2: Not Working Config
                <Directory />
                <Directory /foo>
                                DirectoryIndex foo.html
                <Directory /foo/bar>

Different behavior with <Location>, this works below
                <Location />
                <Location /foo>
                                DirectoryIndex foo.html
                <Location /foo/bar>
                </Location> says the following on section merging
" ... <Directory "/var/web/dir"> will be processed before <Directory "/var/web/dir/subdir">.
If multiple <Directory><>
sections apply to the same directory they are processed in the configuration file order. ..."

View raw message