LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   apache proxy with rewrite problem (https://www.linuxquestions.org/questions/linux-server-73/apache-proxy-with-rewrite-problem-847406/)

xiutuo 11-30-2010 03:23 AM

apache proxy with rewrite problem
 
env: cenots5
apache + tomcat (ajp)
apache ip:192.168.0.100 port 80 ,vhost domain: www.test.com
tomcat1 ip: 192.168.0.101 port 8080
tomcat2 ip:192.168.0.102 port 8080

when visit http://www.test.com/shop/
it actual visit tomcat2 192.168.0.102/shop/index-2000.html
and
http://www.test.com/shop/bottom/reg.html ---->
192.168.0.102/shop/bottom/reg.html

http://www.test.com/shop/other/login.html ---->
192.168.0.102/shop/other/login.html

i use apache rewrite and proxy module(related rewrite proxy module has been compiled and loaded) to do it
my apache confuguration:
Code:

<VirtualHost *:80>
#      DocumentRoot "/apache/htdocs"
      ServerName  www.test.com
RewriteEngine On

RewriteRule  ^(.*)$ http://www.test.com/index-2000.html
  ProxyRequests Off
ProxyMaxForwards 100
ProxyPreserveHost On
ProxyPass / http://192.168.0.102:8080/shop/
ProxyPassReverse / http://192.168.0.102:8080/shop/

<Proxy *>
Order Deny,Allow
Allow from all
</Proxy>
</VirtualHost>

OR
Code:

<VirtualHost *:80>
#      DocumentRoot "/apache/htdocs"
      ServerName  www.test.com
RewriteEngine On

RewriteRule  ^/$ http://www.test.com/index-2000.html
  ProxyRequests Off
ProxyMaxForwards 100
ProxyPreserveHost On
ProxyPass / http://192.168.0.102:8080/shop/
ProxyPassReverse / http://192.168.0.102:8080/shop/

<Proxy *>
Order Deny,Allow
Allow from all
</Proxy>
</VirtualHost>


my question:
it dont work ,why.

if i configure apache like this
Code:

<VirtualHost *:80>
      ServerName  www.test.com

  ProxyRequests Off
ProxyMaxForwards 100
ProxyPreserveHost On
ProxyPass / http://192.168.0.102:8080/shop/index-2000.html
ProxyPassReverse / http://192.168.0.102:8080/shop/index-2000.html

<Proxy *>
Order Deny,Allow
Allow from all
</Proxy>
</VirtualHost>

visit http://www.test.com/shop/
--->192.168.0.102/shop/index-2000.html ok
but
http://www.test.com/shop/bottom/reg.html ---->
192.168.0.102/shop/bottom/reg.html dont work !

http://www.test.com/shop/other/login.html ---->
192.168.0.102/shop/other/login.html dont work !

why...give me a hint!thx

bathory 11-30-2010 03:53 AM

Hi,

Please define "dont work !'
In the meantime, since the URL you're using is http://www.test.com/shop/, why don't you use:
Code:

<VirtualHost *:80>
ServerName  www.test.com
<Proxy *>
 Order Deny,Allow
 Allow from all
</Proxy>

ProxyRequests Off
ProxyMaxForwards 100
ProxyPreserveHost On
ProxyPass /shop http://192.168.0.102:8080/shop
ProxyPassReverse /shop http://192.168.0.102:8080/shop
</VirtualHost>

Regards

xiutuo 12-01-2010 04:05 AM

Quote:

Originally Posted by bathory (Post 4175577)
Hi,

Please define "dont work !'
In the meantime, since the URL you're using is http://www.test.com/shop/, why don't you use:
Code:

<VirtualHost *:80>
ServerName  www.test.com
<Proxy *>
 Order Deny,Allow
 Allow from all
</Proxy>

ProxyRequests Off
ProxyMaxForwards 100
ProxyPreserveHost On
ProxyPass /shop http://192.168.0.102:8080/shop
ProxyPassReverse /shop http://192.168.0.102:8080/shop
</VirtualHost>

Regards


to hidden part of the url "shop/index-2000.html"

if i use
ProxyPass / http://192.168.0.102:8080/shop/
ProxyPassReverse / http://192.168.0.102:8080/shop

i cant let www.test.com ---> www.test.com/shop/index-2000.html
may be rewrite rule has some problem
but
http://www.test.com/shop/bottom/reg.html ---->
192.168.0.102/shop/bottom/reg.html

http://www.test.com/shop/other/login.html ---->
192.168.0.102/shop/other/login.html work fine...

under this configuretion , i just want to let entry www.test.com go to www.test.com/shop/index-2000.html

bathory 12-01-2010 05:56 AM

Hi,

You cannot use mod_rewrite to hide the url, as it runs on apache and for this reason it cannot rewrite urls in tomcat. Even if you stop the reverse proxying of /shop and use mod_rewrite to redirect requests to tomcat, the final url will be shown in the browser address bar, since it's an external rewrite.
I guess you have to deploy the application running on 192.168.0.102, so that the context path is /shop and the index page is index-2000.html.
There is a way to rewrite urls in tomcat using this filter. I've never used it, so I cannot tell if it fits your needs.

Regards


All times are GMT -5. The time now is 11:06 PM.