httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "PAN, JIN" <Jin....@fmr.com>
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
email:

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

Thanks,
Jin

From: PAN, JIN
Sent: Tuesday, November 03, 2015 3:06 PM
To: dev@httpd.apache.org
Subject: Question on multiple <Directory> sections merging

Hi,

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!
-Jin

Filesystem:
                % ls /usr/local/apache2/htdocs
                foo
                % ls /usr/local/apache2/htdocs/foo
                bar
                % ls /usr/local/apache2/htdocs/foo/bar
                foo.html

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

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

Different behavior with <Location>, this works below
                <Location />
                </Location>
                <Location /foo>
                                DirectoryIndex foo.html
                </Location>
                <Location /foo/bar>
                </Location>

https://httpd.apache.org/docs/2.4/sections.html says the following on section merging
" ... <Directory "/var/web/dir"> will be processed before <Directory "/var/web/dir/subdir">.
If multiple <Directory><https://httpd.apache.org/docs/2.4/mod/core.html#directory>
sections apply to the same directory they are processed in the configuration file order. ..."


Mime
View raw message