You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Peter Michaux <pe...@gmail.com> on 2008/11/26 22:40:22 UTC

[users@httpd] configuring disk cache look-up before proxying

I have Apache set up with the following as the first virtual host.
Since the first host is the default, this gives me mass hosting
behavior. Also the back-end server running on port 3000 sees the
original request Host header which it needs to see.

<VirtualHost *:80>
  ServerName example.com
  ProxyPass / http://localhost:3000/
  ProxyPassReverse / http://localhost:3000/
  ProxyPreserveHost on
</VirtualHost>

The back end server caches files in two different places and I would
like Apache to look in those two places and only proxy if the cached
file cannot be found. For example, a request to

http://alpha.example.com/some/page

should first look in

/var/cache/app/alpha.example.com/www/some/page

and then in

/var/lib/app/alpha.example.com/www/some/page

and only proxy the request if those files do not exist.

I have been looking in mod_proxy and mod_cache but am either missing a
piece or cannot see how the pieces fit together.

If anyone has a suggestion for the configuration or which directives
might help, I'd appreciate any advice.

Thank you,
Peter

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] configuring disk cache look-up before proxying

Posted by Peter Michaux <pe...@gmail.com>.
Hi Eric,

On Wed, Nov 26, 2008 at 2:44 PM, Eric Covener <co...@gmail.com> wrote:
> On Wed, Nov 26, 2008 at 4:40 PM, Peter Michaux <pe...@gmail.com> wrote:
>
>> The back end server caches files in two different places and I would
>> like Apache to look in those two places and only proxy if the cached
>> file cannot be found. For example, a request to
>
> Insead of ProxyPass, use mod_rewrite to poke around in the filesystem:
>
> RewriteCond /var/cache/app/%{HTTP_HOST}/%{REQUEST_URI}  -f
> RewriteRule .*  /var/cache/app/%{HTTP_HOST}/%{REQUEST_URI}  [L]
>
> RewriteCond /var/cache/otherapp/%{HTTP_HOST}/%{REQUEST_URI}  -f
> RewriteRule .*  /var/cache/otherapp/%{HTTP_HOST}/%{REQUEST_URI}  [L]
>
> # couldn't find the file in either dir
> RewriteRule ^/(.*) http://localhost:3000/$1 [P]
>
> Or, let Apache cache things instead of writing them to disk, and it
> would be more transparent.
>
> (Note that you need to put the rewrite stuff in per-vhost context,
> otherwise it won't work as-is. You also probably want to handle
> directories if that makes sense for your app (-d))

Thanks for this. I was able to piece together what I needed with your
above idea and some more documentation reading. It seems the [P] uses
mod_proxy and so ProxyPreserveHost is still honoured with the rewrite
rule to localhost:3000.

Thanks,
Peter

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] configuring disk cache look-up before proxying

Posted by Eric Covener <co...@gmail.com>.
On Wed, Nov 26, 2008 at 4:40 PM, Peter Michaux <pe...@gmail.com> wrote:

> The back end server caches files in two different places and I would
> like Apache to look in those two places and only proxy if the cached
> file cannot be found. For example, a request to

Insead of ProxyPass, use mod_rewrite to poke around in the filesystem:

RewriteCond /var/cache/app/%{HTTP_HOST}/%{REQUEST_URI}  -f
RewriteRule .*  /var/cache/app/%{HTTP_HOST}/%{REQUEST_URI}  [L]

RewriteCond /var/cache/otherapp/%{HTTP_HOST}/%{REQUEST_URI}  -f
RewriteRule .*  /var/cache/otherapp/%{HTTP_HOST}/%{REQUEST_URI}  [L]

# couldn't find the file in either dir
RewriteRule ^/(.*) http://localhost:3000/$1 [P]

Or, let Apache cache things instead of writing them to disk, and it
would be more transparent.

(Note that you need to put the rewrite stuff in per-vhost context,
otherwise it won't work as-is. You also probably want to handle
directories if that makes sense for your app (-d))

-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org