Forum Moderators: phranque

Message Too Old, No Replies

Help cleaning up VirtualHost definition

         

iverger

11:41 am on Apr 20, 2007 (gmt 0)

10+ Year Member



Firstly this is Apache 2.0.54 on Linux.

I am hoping to cleanup a growing mess and I am hoping someone can point me in the right direction.

I have a VirtualHost:80 full of redirects to another VirtualHost:443 full of Location tags. Each Location tag has a proxypass/proxyreverse to a backend server. It all works but I am adding a few entries every day and it is getting large, cumbersome and error prone. Is there any way to generalize the redirects and proxypass statements?

The VirtualHost also contains a large amount of static content. (http/https://ua.domain.com/somedir/index.html)

Here is a small sample of the VirtualHost definition:

############################
<VirtualHost ua.domain.com:80>
ServerName ua.domain.com
ProxyPreserveHost On
DocumentRoot "/u02/ua.domain.com"

Redirect /MemberSite [ua.domain.com...]
Redirect /MemberSite_APW [ua.domain.com...]
Redirect /MemberSite_GnG_SCO [ua.domain.com...]
Redirect /AdminWeb_rchag [ua.domain.com...]
Redirect /AdminWeb_bdist [ua.domain.com...]
Redirect /AdminWeb_ctool [ua.domain.com...]
Redirect /WebServices [ua.domain.com...]

</VirtualHost>

<VirtualHost ua.domain.com:443>
ServerName ua.domain.com
ProxyPreserveHost On
DocumentRoot "/u02/ua.domain.com"

<location /MemberSite>
ProxyPass [lwssuse2.backenddomain.net:8096...]
ProxyPassReverse [lwssuse2.backenddomain.net:8096...]
</location>
<location /MemberSite_APW>
ProxyPass [lwssuse2.backenddomain.net:8096...]
ProxyPassReverse [lwssuse2.backenddomain.net:8096...]
</location>
<location /MemberSite_GnG_SCO>
ProxyPass [lwssuse2.backenddomain.net:8096...]
ProxyPassReverse [lwssuse2.backenddomain.net:8096...]
</location>
<location /AdminWeb_rchag>
ProxyPass [lwssuse2.backenddomain.net:8096...]
ProxyPassReverse [lwssuse2.backenddomain.net:8096...]
</location>
<location /AdminWeb_bdist>
ProxyPass [lwssuse2.backenddomain.net:8096...]
ProxyPassReverse [lwssuse2.backenddomain.net:8096...]
</location>
<location /AdminWeb_ctool>
ProxyPass [lwssuse2.backenddomain.net:8096...]
ProxyPassReverse [lwssuse2.backenddomain.net:8096...]
</location>
<location /WebServices>
ProxyPass [lwssuse2.backenddomain.net:8096...]
ProxyPassReverse [lwssuse2.backenddomain.net:8096...]
</location>
</VirtualHost>
############################

Thanks,
Bob

jdMorgan

1:02 pm on Apr 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Look into using RedirectMatch for redirects, and using mod_rewrite instead of ProxyPassReverse. This will enable you to use regular-expressions patterns instead of simple prefix-matching to determine which URLs to act on.

Check carefully to be sure that you really need the ProxyPass directives; Most back-end server setups do not require a forward proxy, and of course, enabling a forward proxy without locking it down exposes your server (and others) to a lot of abuse.

Based on these two observations, I'd recommend a good hard read of Apache's mod_proxy, mod_alias, and mod_rewrite documentation and all supporting material referenced in those documents.

Once you've found a more-efficient method to support your existing setup, the key to avoiding the "ever-growing-list" problem is adopting a standard URL- and/or file- naming convention that explicitly identifies resources that need to be passed to the back-end. For example, if you arrange for all back-end-processed URL-paths to start with "/services/", then it becomes trivial to redirect and reverse-proxy them -- You'd only need two directives to do it, because all they'd have to test is whether the URL-path starts with that string.

Taking this approach, all new URLs would conform to that standard, and you could use RedirectMatch and/or mod_rewrite to redirect the old URLs that don't conform to new ones that do.

Jim