Forum Moderators: phranque

Message Too Old, No Replies

How do I proxy the home page of a site, but not the entire site?

Using mod_proxy

         

jay5r

3:14 pm on Sep 24, 2006 (gmt 0)

10+ Year Member Top Contributors Of The Month



I use Apache to proxy a web application server so the application server doesn't have to deal with anything other than dynamic pages. The issue I can't figure out is how to proxy the home page of the site without redirecting all of the pages on the site to the application server?

If I put in ProxyPass / [127.0.0.1:8080...] everything will get redirected to the application server. Since I do want the home page served by the application server whenever possible, the functional, but inelegant solution that I've come up with is to have two home pages - index.htm (served by the app server), and index.php (served only by Apache). index.php is served for /, and index.htm for /index.htm.

Is there a way to specify that / and only / (not the entire site) should be proxied?

The only solution I can think of is to set up directives to not proxy certain files and directories (using '!'), and then specifying ProxyPass / at the end of the declarations. But then I'd have to specify every directory and file in the root directory. I guess that's not horrible, but is there a way that's more elegant? And if I did that, how what should the ProxyPassReverse declarations look like?

jdMorgan

5:10 pm on Sep 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might want to look into using <Directory> or <FilesMatch>, or <LocationMatch> containers around your proxy directives, in order to make them conditional.

Jim

jay5r

5:51 pm on Sep 24, 2006 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanks, but it didn't seem to work. I just tried:

<LocationMatch "/">
ProxyPass / [127.0.0.1:8080...]
ProxyPassReverse / [127.0.0.1:8080...]
</LocationMatch>

And got the following error when I tried to restart Apache:

Syntax error on line 311 of <filepath>: Invalid ProxyPass parameter. Parameter must be in the form 'key=value'

jdMorgan

6:05 pm on Sep 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



LocationMatch uses regular expressions, so "/" will match any URL-path with a slash in it -- in other words, all paths... Probably not what you want.

<LocationMatch "^/$">

might work better.

Also, as stated in the ProxyPassReverse documentation [httpd.apache.org], you could use the [P] flag on a RewriteRule (see mod_rewrite) instead of ProxyPass to selectively proxy requests to your back-end server if the <Location> container isn't working for you.

Jim

[edited by: jdMorgan at 6:06 pm (utc) on Sep. 24, 2006]

jay5r

6:38 pm on Sep 24, 2006 (gmt 0)

10+ Year Member Top Contributors Of The Month



Jim - Thanks for the help!

The following works great...

RewriteRule ^/$ [127.0.0.1:8080...] [P]