Forum Moderators: phranque

Message Too Old, No Replies

Proxying specific filetypes to another server

         

Forse

2:05 am on Dec 28, 2006 (gmt 0)

10+ Year Member



Hello guys.

I was wondering if any of you knows how to configure apache in such matter that it uses my another server running on www.somehost:8020 for images and such.

Basicly I have website with a lot of images and I would like thttpd to take care of serving static files so apache only handles php files.

I was looking into something like:

ProxyRequests Off
ProxyPreserveHost On
ProxyPass /images http://www.somehost.com:8020/
ProxyPassReverse / http://www.somehost.com:8020/

But this would mean that apache still fetches the page from my thttpd server right? Meaning I am not reducting overhead, but maybe even increasing it because:

client requests bla.jpg->apache requests image from thttpd->thttpd serves it to apache->apache then serves it to client

If this is the case then I am not sure if this will reduce my server load at all. My another alternative I guess is mod_rewrite, but won't it send 302 header?

Sorry if this all sounds confusing, but I am not sure if I can explain it any better then this.

Hope you can help me or suggest some docs I could read, thank you.

P.S. I also don't mind if urls to images have port 8020 in them.

jdMorgan

2:21 am on Dec 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Using a back-end server to serve images, etc. will improve the performance of the front-end server, because all it then has to do is to handle the incoming request, pass it to the back-end, and then pipe the resulting back-end response back to the requestor. While this may sound like a lot, remember what it does not have to do: It doesn't have to handle the URL-to-filename translation, file-exists checks, filesystem and disk controller requests, disk I/O, response header creation, etc. You may find that your actual performance increase on the front-end is driven mostly by the great reduction in disk activity, rather than anything else. You should also see a noticeable reduction in CPU utilization as well, though, meaning more CPU availabilty to process your scripts.

You don't actually need the ProxyPass stuff, since all you're doing is a reverse Proxy here -- See the mod_proxy docs.

If you wish to reverse proxy by filetype, then you'll probably want to use mod_rewrite to do it, since all of the native mod_proxy directives use URL prefix-matching only, as opposed to the suffix-matching you likely want. This is easily done using the [P] flag on a RewriteRule (Follow the link in the mod_proxy ProxyPassReverse documentation).

[added] No, a proxy pass-through in mod_rewrite is *not* a redirect. [/added]

Jim

[edited by: jdMorgan at 2:22 am (utc) on Dec. 28, 2006]