I'm having a lot of troubles with the propper configuration of Apache mod_proxy.so to work as desired...

The main idea, is to create a proxy on a local machine in a network wich will have the ability to proces a client request (client connected through this Apache prepared proxy) in PHP. And also, it will have the capacity to process the server responses on PHP too.

Those are the 2 funcionalities, and they are independent one from each other.

Let me present a little schema of what I need to achive:

alt text

As you can see here, there're 2 ways: blue one and red one.

For the blue one, I basically conected a client (Machine B - cell phone) on my local network (home) and configured it to go thorugh a proxy, wich is the Machine A (personal computer) on the exactly same network.

So let's say (not DHCP):

Machine A: 192.168.1.40 --> Apache is running on this machine, and configured to listen port 80.

Machine B (cell phone): 192.168.1.75 --> configured to go throug a proxy, wich is IP 192.168.1.75 and port 80 (basically, Machine A).

After configuring Apache properly, wich is basically to remove the "#" from httpd.conf on the lines for the mod_proxy.so (main worker), mod_proxy_connect.so (SSL, allowCONNECT, ...) and mod_proxy_http.so (needed for handle HTTP request/responses) and having in my case, lines like this:

# Implements a proxy/gateway for Apache.
Include "conf/extra/httpd-proxy.conf"

# Various default settings
Include "conf/extra/httpd-default.conf"

# Secure (SSL/TLS) connections
Include "conf/extra/httpd-ssl.conf"

wich gives me the ability to configure the file httpd-proxy.conf to prepare the forward proxy or the reverse proxy.

So I'm not sure, if what I need it's a forward proxy or a reverse one.

For a forward proxy I've done this:

<IfModule proxy_module>
<IfModule proxy_http_module>

#
# FORWARD Proxy
#

#ProxyRequests Off
ProxyRequests On
ProxyVia On

<Proxy *>
    Order deny,allow
#   Allow from all
    Deny from all
    Allow from 192.168.1
</Proxy>

</IfModule>
</IfModule>

wich basically passes all the packets normally to the server and back to the client. I can trace it perfectly (and testing that works) looking at the "access.log" from Apache. Any request I make with the cell phone, appears then on the Apache log. So it works.

But here come the problem:

  • I need to process those client requests. And I need to do it, in PHP.

I have read a lot about this. I've read in detail the oficial site from Apache about mod_proxy. And I've searched a lot on forums, but without luck.

So I thought about a first aproximation:

1) Forward proxy in Apache, passes all the packets and it's not possible to process them. This seems to be true, so, what about a reverse proxy?

So I envisioned something like:

ProxyRequests Off

<Proxy *>
Order deny,allow
Allow from all
</Proxy>

ProxyPass http://www.google.com http://www.yahoo.com
ProxyPassReverse http://www.google.com http://www.yahoo.com 

which is just a test, but this should cause on my cell phone that when trying to navigate to Google, I should be going to Yahoo, isn't it? But not. It doesn't work.

So you really see, that ALL the examples on Apache reverse proxy, goes like:

ProxyPass /foo http://foo.example.com/bar
ProxyPassReverse /foo http://foo.example.com/bar

wich means, that any kind of request in a local context, will be solved on a remote location.

But what I needed is the inverse! It's that when asking for a remote site on my phone, I solve this request on my local server (the Apache one) to process it with a PHP module.

So, if it's a forward proxy, I need to pass through PHP first. If it's a reverse proxy, I need to change the "going" direction to my local server one to process first on PHP.

Then comes in mind second option:

2) I've seen something like:

<Proxy http://example.com/foo/*>
SetOutputFilter INCLUDES
</Proxy>

And I started to search for SetOutputFilter, SetInputFilter, AddOutputFilter and AddInputFilter.

But I don't really know how can I use it.

Seems to be good, or a solution to me, cause with somethin' like this, I should can add an Input filter to process on PHP the client requests and send back to the client what I programed/want (not the remote server response) wich is the BLUE path on schema, and I should have the ability to add an Output filter wich seems to give me the ability to process the remote server response befor sending it to the client, wich should be the RED path on the schema.

Red path, it's just to read server responses and play with em. But nothing more. The Blue path, it's the important one. Cause I will send to the client whatever I want after procesing the requests.

I so sorry for this amazingly big post, but I needed to explain it as well as I can.

I hope someone will understand my problem, and will help me to solve it!

Lot of thanks in advance!! :)

link|improve this question
How is this a programming question? – netcoder Jan 14 '11 at 20:29
It's not a "programming" question itself, but it's pretty related! I need to know how to achive Apache to handle requests and responses via PHP on demand, on certain domain (i.e: YouTube.com) – Lightworker Jan 14 '11 at 21:40
@Lightworker - I'm migrating this to ServerFault.com, it's another site in the trilogy and much better venue specifically with experts in this area. Your question is programming related yes, but it's much more on topic at ServerFault, where it'll find a quicker/better answer. – Nick Craver Jan 15 '11 at 12:09
I need to achive Apache work as a proxy, and when a client request - connected through the Apache proxy - comes from YouTube (i.e.), send this request to a PHP module to process an specific answer and send it to the requesting client. :\ – Lightworker Jan 15 '11 at 17:57
feedback

migrated from stackoverflow.com Jan 15 '11 at 12:09

This question came from our site for professional and enthusiast programmers.

1 Answer

Okay, so first of all: Apache is the wrong tool!

Apache is a webserver, not a proxy server. Yes, it comes with a proxy module, but first and foremost it's a webserver.

Rather, you should look into a real proxy server like squid. And within squid you are looking for a feature called "Content Adaptation":

http://wiki.squid-cache.org/SquidFaq/ContentAdaptation

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.