back in 1998 and 99 there was a longer discussion about scoping problems
with PerlSetEnv (inside httpd.conf and .htaccess files), which ended
with fixes applied to mod_perl-1.20, which is the version I have been
using (along with apache-1.3.6 and perl 5.00404)

Now I am setting up a brand new machine to replace my aging web server
and compiled Perl 5.6.1, apache_1.3.20, and mod_perl-1.25 (Solaris 8)
and the old problem is back, only worse. This is so severe I can't
imagine it happening in all configurations out there, but here is
what I found.

Summary:

1 a variable defined with PerlSetEnv in the main server (outside any
  virtual hosts) cannot be changed inside a virtual host section (the
  change is ignored)

2 a variable defined inside a virtual host section is visible to all
  *other* virtual hosts and the main server

3 a variable defined in httpd.conf cannot be changed inside a .htaccess
  file (the change is ignored)


I set up my Apache with a minimal httpd.conf and two IP-based
virtual hosts (besides the main server), configured like this
(plus the necessary "AllowOverride All", etc.; see attached file)

    # main server
    
    DocumentRoot "/www/test/root"
    
    PerlSetEnv VarA Global
    PerlSetEnv VarB Global
    
    
    # virthost 1
    
    <VirtualHost IP1>
    DocumentRoot "/www/test/root1"
    
    PerlSetEnv VarA VirtHost1
    PerlSetEnv VarC VirtHost1
    
    </VirtualHost>
    
    
    # virthost 2
    
    <VirtualHost IP2>
    DocumentRoot "/www/test/root2"
    
    PerlSetEnv VarA VirtHost2
    
    </VirtualHost>


additionally, /www/test/root2 contains this .htaccess file

    PerlSetEnv VarB root2
    PerlSetEnv VarD root2


Using a Apache::Registry script to print the enviroment in all three
servers (main and the two virtual hosts), I get these values

Var     main            virthost1       virthost2

VarA    Global          Global*         Global*
VarB    Global          Global          Global*
VarC    VirtHost1*      VirtHost1       VirtHost1*
VarD    -               -               root2

the entries with the * are wrong, I think.

Has anyone seen something like this before?


Regards,

Roman Maeder

##
## httpd.conf -- Apache HTTP server configuration file
##

ServerType standalone

ServerRoot "/www/apache"

PidFile logs/httpd.pid

ScoreBoardFile logs/httpd.scoreboard

ResourceConfig /dev/null
AccessConfig /dev/null

MinSpareServers 5
MaxSpareServers 10
StartServers 5

#
# Dynamic Shared Object (DSO) Support
#
LoadModule env_module         libexec/mod_env.so
LoadModule config_log_module  libexec/mod_log_config.so
LoadModule mime_module        libexec/mod_mime.so
LoadModule status_module      libexec/mod_status.so
LoadModule info_module        libexec/mod_info.so
LoadModule autoindex_module   libexec/mod_autoindex.so
LoadModule dir_module         libexec/mod_dir.so
LoadModule cgi_module         libexec/mod_cgi.so
LoadModule alias_module       libexec/mod_alias.so
LoadModule access_module      libexec/mod_access.so
LoadModule headers_module     libexec/mod_headers.so

#  Reconstruction of the complete module list from all available modules
#  (static and shared ones) to achieve correct module execution order.
#  [WHENEVER YOU CHANGE THE LOADMODULE SECTION ABOVE UPDATE THIS, TOO]
ClearModuleList
AddModule mod_env.c
AddModule mod_log_config.c
AddModule mod_mime.c
AddModule mod_status.c
AddModule mod_info.c
AddModule mod_autoindex.c
AddModule mod_dir.c
AddModule mod_cgi.c
AddModule mod_alias.c
AddModule mod_access.c
AddModule mod_headers.c
AddModule mod_so.c
AddModule mod_perl.c

AddHandler cgi-script .cgi

### Section 2: 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition.  These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#

Port 80

User httpd
Group httpd

AccessFileName .htaccess

DefaultType text/plain

HostnameLookups On

ErrorLog logs/test-error.log
LogLevel info

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

CustomLog logs/test-access.log combined


PerlSendHeader On
<Files *.pl>
SetHandler perl-script
PerlHandler Apache::Registry
Options +ExecCGI
</Files>
AddType text/html .pl


# main server

DocumentRoot "/www/test/root"

<Directory "/www/test/root">
    Options All
    AllowOverride All
</Directory>

PerlSetEnv VarA Global
PerlSetEnv VarB Global


# virthost 1

<Directory "/www/test/root1">
    Options All
    AllowOverride All
</Directory>

<VirtualHost vvv-mc>
DocumentRoot "/www/test/root1"

PerlSetEnv VarA VirtHost1
PerlSetEnv VarC VirtHost1

</VirtualHost>


# virthost 2

<Directory "/www/test/root2">
    Options All
    AllowOverride All
</Directory>

<VirtualHost vvv-md>
DocumentRoot "/www/test/root2"

PerlSetEnv VarA VirtHost2

</VirtualHost>

Reply via email to