I have a seemingly un-unique problem with two Drupal 6 sites that I am
attempting to solve with Apache ProxyPass and have not come upon a working
configuration. Here I will explain my setup and the changes I've tried.
The goal is to have sub.sitename.org serve anything starting with /subsite
and for www.sitename.org to serve everything else, with the client being
unaware of the separation. This subsite will eventually be folded into the
main site, but for now we need to create the illusion of unity.
Example of desired result:
www.sitename.org -> /var/www/mainsite/htdocs/index.php
www.sitename.org/resource -> /var/www/mainsite/htdocs/index.php?q=resource
www.sitename.org/resource/subresource -> /var/www/mainsite/htdocs/index.php?q=resource/subresource
www.sitename.org/subsite/resource -> /var/www/subsite/htdocs/index.php?q=subsite/resource
It is not important which site serves ?q=subsite, as they are the same on both,
but only the subsite has the rest of the content underneath that.
Technical Details:
Server: CentOS 5.8
Apache Version: 2.2.17
PHP Version: 5.2.17
Main site Drupal Version: 6.19
Subsite Drupal Version: 6.22
Initial Setup:
VirtualHost one (main site):
<VirtualHost *:80>
ServerName www.sitename.org
DocumentRoot /var/www/mainsite/htdocs
DirectoryIndex index.php index.html index.htm
<Directory /var/www/mainsite/htdocs>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>
</VirtualHost>VirtualHost two (subsite):
<VirtualHost *:80>
ServerName sub.sitename.org
DocumentRoot /var/www/subsite/htdocs
<Directory /var/www/subsite/htdocs>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>
</VirtualHost>
(A note: The Rewrite configuration is held in an included file: drupal-clean-urls.conf,
but I have expanded it here for clarity)
So, currently www.sitename.org and subsite.sitename.org work perfectly fine,
though 'subsite' only contains content under subsite.sitename.org/subsite
(If that's not redundant enough for you, one of the issues this is supposed to resolve.)
The subsite is a multisite, in which the site is contained in sites/subsite.sitename.org
We are currently working with another site that has a similar setup, but is
simply being redirected, so a directive like this is sufficient:
RedirectMatch permanent ^/subsite/(.*)$ http://other.site.org/subsite/$1
However, in this instance, the requirement is for the client to be unaware of the change,
thus a Proxy is needed.
First attempt was to add a RewriteRule with the [P] option in the main site VirtualHost, to proxy:
<VirtualHost *:80>
ServerName www.sitename.org
DocumentRoot /var/www/mainsite/htdocs
DirectoryIndex index.php index.html index.htm
RewriteEngine on
RewriteRule ^/subsite/(.*)$ http://subsite.sitename.org/subsite/$1 [P]
<Directory /var/www/mainsite/htdocs>
Include drupal-clean-urls.conf
</Directory>
</VirtualHost>
This did not work. After a considerable time (30 seconds, probably for a timeout),
I get back a 503 Service Temporarily Unavailable message when I try to access:
http://www.sitename.org/subsite/resource.
I read that Drupal needs to know if it's behind a reverse proxy, so I uncommented a few lines in
the settings.php for the subsite, with the private and public IPs being actual IPs of course:
$conf = array(
'reverse_proxy' => TRUE,
'reverse_proxy_addresses' => array('localhost','127.0.0.1','private_lan_ip','public_world_ip')
);
After saving, and restarting Apache, refreshing the page results in the same error,
while other resources on the main site and directly accessing the subsite succeed.
I then tried using ProxyPass directly, as follows:
<VirtualHost *:80>
ServerName www.sitename.org
DocumentRoot /var/www/mainsite/htdocs
DirectoryIndex index.php index.html index.htm
ProxyPass /subsite/ http://subsite.sitename.org/subsite/
ProxyPassReverse /subsite/ http://subsite.sitename.org/subsite/
<Directory /var/www/mainsite/htdocs>
Include drupal-clean-urls.conf
</Directory>
</VirtualHost>
According to http://drupal.org/node/440498, this should work beautifully. Though, my situation is local.
However, I still get the same result (503 Service Temporarily Unavailable) after an apache restart
I have also tried many variations of the above, mostly with ProxyPass and related directives
including ProxyPassReverseCookiePath and ProxyPassReverseCookieDomain,
as well as changing the settings.php base_url and cookie_domain,
but I have been unable to even get it to serve the correct content from the correct domain!
Is there something (surely) I am missing? Have I duplicated work somewhere that's causing a loop?
memcache is on and being used for the main site, but that shouldn't matter, should it?
Here is a list of sites I have consulted in my vain attempts to make this come together:
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
http://www.scalingbits.com/drupal/apacheproxy
http://drupal.org/node/1358312 - Not quite the same, as I have two drupal sites, one a subset of the other
http://drupal.org/node/1222276 - I don't have session issues (yet), I'm just trying to get it to load!
http://drupal.org/node/469080 - This person was also having issues 3 years ago, and apparently never got it resolved.
http://www.linuxquestions.org/questions/linux-server-73/url-redirection-...
http://objectmix.com/apache/655118-re-rewrite-but-keep-original-url-brow...
http://marc.info/?l=apache-httpd-users&m=104313810504362&w=2