Feature #2383

mod_alias: use alias directory as doc-root too

Added by molliver about 5 years ago. Updated 11 months ago.

Target version:
Start date:
Due date:
% Done:


Missing in 1.5.x:


11:23 <darix> we just wrap that 1 line into an option
11:23 <darix> something like alias.update-docroot or so
11:24 <darix> then pixie79 and others can have change the behavior and we dont break the rest
11:24 <stbuehler> i'm lazy and wait for a patch :P

diff --git a/src/mod_alias.c b/src/mod_alias.c
index 5b7b510..6702bbc 100644
--- a/src/mod_alias.c
+++ b/src/mod_alias.c
@@ -173,6 +173,9 @@ PHYSICALPATH_FUNC(mod_alias_physical_handler) {
                        /* matched */

                        buffer_copy_string_buffer(con->physical.basedir, ds->value);
+            if (0 == (con->conf.alias.update-docroot->used == 0) {
+                buffer_copy_string_buffer(con->physical.doc_root, ds->value);
+            }
                        buffer_copy_string_buffer(srv->tmp_buf, ds->value);
                        buffer_append_string(srv->tmp_buf, uri_ptr + alias_len);
                        buffer_copy_string_buffer(con->physical.path, srv->tmp_buf);

Associated revisions

Revision a0a7b9fb (diff)
Added by gstrauss 11 months ago

[mod_ssi, mod_cml] set DOCUMENT_ROOT to basedir (fixes #2383)

fixes inconsistency w/ mod_fastcgi, mod_scgi, mod_cgi change in adc97e5b

"mod_alias: use alias directory as doc-root too"
"mod_userdir doesn't set environment variable DOCUMENT_ROOT"


#1 Updated by stbuehler about 5 years ago

  • Description updated (diff)
  • Target version changed from 1.4.31 to 1.4.x

#2 Updated by stbuehler almost 5 years ago

  • Description updated (diff)

#3 Updated by stbuehler almost 5 years ago

This patch won't work. C (and lighttpd) is a little bit more complex.

#4 Updated by gstrauss about 1 year ago

It seems some context from IRC did not make it into the issue description. What was/is the intent?

#5 Updated by stbuehler about 1 year ago

  • Subject changed from mod_alias to mod_alias: use alias directory as doc-root too

#6 Updated by stbuehler about 1 year ago

IIRC the intention was that the backend gets a "physical base directory" as docroot to search for application specific configurations (e.g.

#7 Updated by gstrauss 11 months ago

  • Status changed from New to Need Feedback

DOCUMENT_ROOT is not part of the CGI specification ( describes numerous ways to attempt to reverse engineer $_SERVER['DOCUMENT_ROOT'] if not provided (for whatever reason)

Since lighttpd sets DOCUMENT_ROOT for the benefit of PHP, why not always set DOCUMENT_ROOT to con->physical.basedir instead of con->physical.doc_root?

Note: con->physical.basedir is equivalent to con->physical.doc_root, unless con->physical.basedir has been changed by modules such as mod_alias and mod_userdir, among others. It seems like an oversight that this is not already the case. When the base directory changes it is surprising that such is not reflected in DOCUMENT_ROOT.

(I understand that changing this now is a behavior change which might surprise some people, so perhaps there should be a server directive to user con->physical.basedir when setting DOCUMENT_ROOT in CGI, FastCGI, SCGI, and SSI.)

#8 Updated by gstrauss 11 months ago

mod_fastcgi, mod_scgi, and mod_cgi already set DOCUMENT_ROOT to con->physical.basedir. Only mod_ssi and mod_cml_lua do not, and those should probably be considered bugs. (Why does mod_cml_lua set the PHP env var DOCUMENT_ROOT at all?)

See #2216

commit adc97e5ba3f4b42afd2ed1b0d689565dc67736e8
Author: Stefan B├╝hler <>
Date:   Mon Jun 13 12:22:02 2011 +0000

    [*cgi] Use physical base dir (alias, userdir) as DOCUMENT_ROOT in cgi environments (fixes #2216)

    git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9

What the issue in this ticket already (mostly) solved before this ticket was created?

#9 Updated by gstrauss 11 months ago

A post in 2014 at points out the inconsistency in mod_ssi and mod_cml_lua

#10 Updated by gstrauss 11 months ago

  • Status changed from Need Feedback to Patch Pending
  • Target version changed from 1.4.x to 1.4.40
diff --git a/src/mod_cml_lua.c b/src/mod_cml_lua.c
index 519f9c8..67f989e 100644
--- a/src/mod_cml_lua.c
+++ b/src/mod_cml_lua.c
@@ -152,7 +152,7 @@ int cache_parse_lua(server *srv, connection *con, plugin_data *p, buffer *fn) {
                c_to_lua_push(L, header_tbl, CONST_STR_LEN("REQUEST_URI"), CONST_BUF_LEN(con->request.orig_uri));
                c_to_lua_push(L, header_tbl, CONST_STR_LEN("SCRIPT_NAME"), CONST_BUF_LEN(con->uri.path));
                c_to_lua_push(L, header_tbl, CONST_STR_LEN("SCRIPT_FILENAME"), CONST_BUF_LEN(con->physical.path));
-               c_to_lua_push(L, header_tbl, CONST_STR_LEN("DOCUMENT_ROOT"), CONST_BUF_LEN(con->physical.doc_root));
+               c_to_lua_push(L, header_tbl, CONST_STR_LEN("DOCUMENT_ROOT"), CONST_BUF_LEN(con->physical.basedir));
                if (!buffer_string_is_empty(con->request.pathinfo)) {
                        c_to_lua_push(L, header_tbl, CONST_STR_LEN("PATH_INFO"), CONST_BUF_LEN(con->request.pathinfo));
diff --git a/src/mod_ssi.c b/src/mod_ssi.c
index 9172fa2..8d4452a 100644
--- a/src/mod_ssi.c
+++ b/src/mod_ssi.c
@@ -283,7 +283,7 @@ static int build_ssi_cgi_vars(server *srv, connection *con, plugin_data *p) {

        ssi_env_add(p->ssi_cgi_env, CONST_STRING("SCRIPT_FILENAME"), con->physical.path->ptr);
-       ssi_env_add(p->ssi_cgi_env, CONST_STRING("DOCUMENT_ROOT"), con->physical.doc_root->ptr);
+       ssi_env_add(p->ssi_cgi_env, CONST_STRING("DOCUMENT_ROOT"), con->physical.basedir->ptr);

        ssi_env_add(p->ssi_cgi_env, CONST_STRING("REQUEST_URI"), con->request.uri->ptr);

#11 Updated by gstrauss 11 months ago

  • Status changed from Patch Pending to Fixed
  • % Done changed from 0 to 100

Also available in: Atom