You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Venkat Rangan <ve...@clearwellsystems.com> on 2008/03/20 07:10:01 UTC

[users@httpd] Apache reverse-proxy config.

Hi,

 

I am looking to deploy Apache 2.2 on a Windows box as a reverse-proxy to
two servers. The following is what I have in httpd.conf on the
reverse-proxy.

 

 

<VirtualHost *:*>

ProxyPreserveHost On

ProxyHTMLLogVerbose On

ProxyPass /app http://XX.XX.XX.XX/app

ProxyPassReverse /app http://XX.XX.XX.XX/app

ProxyHTMLURLMap http://192.168.122.184/app /app

</VirtualHost>

 

<VirtualHost *:*>

ProxyPreserveHost On

ProxyHTMLLogVerbose On

ProxyPass /backup/app http://YY.YY.YY.YY/app

ProxyPassReverse /backup/app http://YY.YY.YY.YY/app

ProxyHTMLURLMap http://YY.YY.YY.YY/app /backup/app

</VirtualHost>

 

The first server XX.XX.XX.XX is the main application and the proxy is
able to redirect browser requests without any problems. However, the
second server is not reachable through the proxy.

 

I turned on LogLevel Debug and the proxy's error.log has the following.

 

[Wed Mar 19 22:08:20 2008] [error] [client XX.XX.ZZ.ZZ] File does not
exist: C:/Program Files/Apache Software
Foundation/Apache2.2/htdocs/backup

 

Also, the direct access to second server, bypassing the proxy, using
http://YY.YY.YY.YY/app works fine, both from the browser client as well
as from the proxy.

 

Is there anything I am missing?

 

Thanks.


RE: [users@httpd] Apache reverse-proxy config.

Posted by Venkat Rangan <ve...@clearwellsystems.com>.
Nils,

Thanks very much for your help.

I have made some progress - but still do not have a solution. My snippet
from httpd.conf on the Proxy Server (192.168.121.214) is:

NameVirtualHost 192.168.121.214:8080

<VirtualHost 192.168.121.214:8080>
ServerName test1
ProxyPreserveHost On

ProxyPass /testcase1/app http://192.168.122.184/app
ProxyPassReverse /testcase1/app http://192.168.122.184/app
ProxyHTMLURLMap http://192.168.122.184/app /testcase1/app

ProxyPass /testcase2/app http://192.168.122.247/app
ProxyPassReverse /testcase2/app http://192.168.122.247/app
ProxyHTMLURLMap http://192.168.122.247/app /testcase2/app

ErrorLog c:/temp/test-error.log

</VirtualHost>

My goal is the following:

Browser sends requests to the following to the proxy. (I have my DNS set
to resolve test1 to 192.168.121.214)

Request-1:
http://test1:8080/testcase1/app

Request-2:
http://test1:8080/testcase2/app

I want the Proxy Server (192.168.121.214:8080) to route:
Request-1 to: http://192.168.122.184/app
Request-2 to: http://192.168.122.247/app

It doesn't work - produces a 404 Not Found error and the Proxy Server
has the following in its access.log.

192.168.12.127 - - [20/Mar/2008:16:00:28 -0700] "GET /testcase1/app
HTTP/1.0" 302 -
192.168.12.127 - - [20/Mar/2008:16:00:28 -0700] "GET /app/ HTTP/1.0" 404
202
192.168.12.127 - - [20/Mar/2008:16:15:31 -0700] "GET /testcase2/app
HTTP/1.0" 302 -
192.168.12.127 - - [20/Mar/2008:16:15:31 -0700] "GET /app/ HTTP/1.0" 404
202


On the other hand, if I create two separate VirtualHosts such as the
following.

NameVirtualHost 192.168.121.214:8080

<VirtualHost 192.168.121.214:8080>
ServerName test1
ProxyPreserveHost On

ProxyPass /app http://192.168.122.184/app
ProxyPassReverse /app http://192.168.122.184/app
ProxyHTMLURLMap http://192.168.122.184/app /app

ErrorLog c:/temp/test1-error.log

</VirtualHost>

<VirtualHost 192.168.121.214:8080>
ServerName test2
ProxyPreserveHost On

ProxyPass /app http://192.168.122.247/app
ProxyPassReverse /app http://192.168.122.247/app
ProxyHTMLURLMap http://192.168.122.247/app /app

ErrorLog c:/temp/test2-error.log

</VirtualHost>

Now, if I have DNS resolve both test1 and test2 to the same Proxy IP
Address (192.168.121.214), and issue http://test1:8080/app, or
http://test2:8080/app, everything works fine and the requests go to the
right Origin Servers. For success case, the Access Log has:

192.168.12.127 - - [20/Mar/2008:12:58:15 -0700] "GET /app HTTP/1.1" 302
-
192.168.12.127 - - [20/Mar/2008:12:58:15 -0700] "GET
/app/goToUserHome.do HTTP/1.1" 200 36175

Note that there is an additional JavaScript, in the response from the
Origin Server in both cases - 'wget http://192.168.122.184/app' on the
proxy produces the following HTML.

<html>
    <head>
        <title>Go To Home Page</title>
        <script language="JavaScript1.2">
            function goToHomePage() {
            	location.replace("/app/goToUserHome.do");
            }
        </script>
    </head>
    <body onLoad="goToHomePage()">
        &nbsp;
    </body>
</html>

For some reason, when I have two VirtualHosts, the JavaScript is
properly recognized and re-issued by the Proxy. If I have one
VirtualHost with two separate path-based ProxyPass, the above GET
doesn't happen.

Is there something I am missing in the Proxy httpd.config? Do I need
some kind of a re-write rule?

Thanks.


-----Original Message-----
From: Nils Jeppe [mailto:nils@pandemonium.de] 
Sent: Thursday, March 20, 2008 12:46 AM
To: users@httpd.apache.org
Subject: Re: [users@httpd] Apache reverse-proxy config.



On Wed, 19 Mar 2008, Venkat Rangan wrote:

> Is there anything I am missing?

Yes. Apache is not able to distinguish between your two virtualhosts,
and 
thus using the first one. Use NameVirtualHost on the IP (or *) in the
main 
part of your config and assign ServerName 's to each of the
virtualhosts. 
I think this should solve your problem.


Best wishes,
Nils




---------------------------------------------------------------------
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


---------------------------------------------------------------------
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] Apache reverse-proxy config.

Posted by Nils Jeppe <ni...@pandemonium.de>.

On Wed, 19 Mar 2008, Venkat Rangan wrote:

> Is there anything I am missing?

Yes. Apache is not able to distinguish between your two virtualhosts, and 
thus using the first one. Use NameVirtualHost on the IP (or *) in the main 
part of your config and assign ServerName 's to each of the virtualhosts. 
I think this should solve your problem.


Best wishes,
Nils




---------------------------------------------------------------------
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