views:

983

answers:

2

How can I set up a reverse proxy with mod_proxy without redirecting to another server or IP? This will be a virtual host environment. The reason I want to do this is so that mod_proxy handles the communication with the client's browser thereby freeing up web server processes to serve the next request instead of feeding the client's browser. This is especially important when using language modules such as mod_php with MPM Prefork. The flow that I'm trying to achieve is: 1. The traffic resolves to www.mydomain.com on port 80. 2. The proxy sends the request the web server. 3. The web server sends the answer back to the proxy and disconnects from the proxy. 4. The proxy feeds the client browser.

Once that is working I want to add nginx at the same IP address but for port 81 and proxy image requests to nginx on the same server. I do not want nginx handling the proxy nor do I want FCGI anything. I want my standard Apache mod_rewrite and .htaccess to work.

Thanks Tons!

+2  A: 

Simply redirect to the localhost on a different port? Host your application on port 8080, and use mod_proxy to forward the requests:

ProxyPass /foo http://localhost:8080/foo
ProxyPassReverse /foo http://localhost:8080/foo

This may be helpful if you have application servers that are handling requests and you want multiple instances combined on a single machine. You can use one port per application server.

I don't know if it really would be faster than just using mod_php directly. Proxying requests also adds overhead.

molf
I think that's perfect. I didn't think of having Apache listen on multiple ports. Whether or not it relieves any load depends on how much time the mod_php processes are actually spending feeding the browser and what the keep-alive impact is. If most of the requests fit into the socket buffer, then Apache isn't doing the communication "baby sitting" anyway, the kernel is, and I cannot do any better than that. The proxy also allows me to try nginx for static content. That MAY help. The PHP cache is working great. After these tweaks it's down to lingerd, buffers, CPU, and RAM.
A: 

Make sure you also use load these 2 modules

LoadModule proxy_module bin/mod_proxy.so 
LoadModule proxy_http_module bin/mod_proxy_http.so

ProxyPass /TeamCity http://localhost/TeamCity
ProxyPassReverse /TeamCity http://localhost/TeamCity
dvkwong