LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-30-2010, 03:23 AM   #1
xiutuo
Member
 
Registered: Mar 2008
Posts: 55

Rep: Reputation: 15
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

Last edited by xiutuo; 11-30-2010 at 03:29 AM.
 
Old 11-30-2010, 03:53 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,159
Blog Entries: 1

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
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
 
Old 12-01-2010, 04:05 AM   #3
xiutuo
Member
 
Registered: Mar 2008
Posts: 55

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by bathory View Post
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

Last edited by xiutuo; 12-01-2010 at 04:09 AM.
 
Old 12-01-2010, 05:56 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,159
Blog Entries: 1

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling all Apache proxy/rewrite gurus viGeek Linux - Server 1 07-27-2010 06:52 PM
Apache virtual host, rewrite & proxy question NickDeGraeve Linux - Server 8 02-02-2009 07:09 PM
How do I get Apache Rewrite to proxy two domains ? anon252 Linux - Server 1 11-28-2008 05:16 AM
Problem with Apache rewrite griffey Linux - Software 1 08-10-2007 06:19 AM
apache proxy server rewrite urls slackwarefan Linux - Software 0 10-19-2004 07:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration