Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a reverse proxy Apache that is moving the request to a Tomcat servlet. The configuration on the Virtual Host in Apache is:

<VirtualHost 10.10.10.10:80>
ProxyPass /Site1/ServLet1 http://1.1.1.1/Site1/ServLet1
ProxyPassReverse /Site1/ServLet1 http://1.1.1.1//Site1/ServLet1

ProxyPass /Site2/ServLet2 http://2.2.2.2/Site2/ServLet2
ProxyPassReverse /Site2/ServLet2 http://2.2.2.2/Site1/ServLet1
</VirtualHost>

Essentially, if it comes to 10.10.10.10 and requests /Site1/ServLet1, route it to /Site1/ServLet1.

if I add

<VirtualHost 10.10.10.10:80>
ProxyPass /Site1/ServLet1 http://1.1.1.1/Site1/ServLet1
ProxyPassReverse /Site1/ServLet1 http://1.1.1.1//Site1/ServLet1
ErrorDocument 404 /customerrors/site1/404.html

ProxyPass /Site2/ServLet2 http://2.2.2.2/Site2/ServLet2
ProxyPassReverse /Site2/ServLet2 http://2.2.2.2/Site1/ServLet1
</VirtualHost>

so it will show a custom error for site1 (I set the ErrorDocument), it will be served to both.

How can I have a different 404 error page per site maintaining this kind of configuration?

Thank

Edit:

if I modify the configuration based on the comments below like:

<Location /Site1/ServLet1/>
ProxyPass http://1.1.1.1/Site1/ServLet1
ProxyPassReverse http://1.1.1.1/Site1/ServLet1
ErrorDocument 404 /customerrors/site1/404.html
</Location>

Then I can still get to http://1.1.1.1/Site1/ServLet1 but no error page is displayed whatsoever

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

I'm not sure what you mean by "different VirtualHosts", since these are in the same one.. but I think you'll want to do something like this (and consider moving the ProxyPass statements into the <Location> blocks too, if you can):

<VirtualHost 10.10.10.10:80>
    ProxyPass /Site1/ServLet1 http://1.1.1.1/Site1/ServLet1
    ProxyPassReverse /Site1/ServLet1 http://1.1.1.1/Site1/ServLet1

    <Location /Site1>
        ErrorDocument 404 /customerrors/site1/404.html
    </Location>

    ProxyPass /Site2/ServLet2 http://2.2.2.2/Site2/ServLet2
    ProxyPassReverse /Site2/ServLet2 http://2.2.2.2/Site2/ServLet2

    <Location /Site2>
        ErrorDocument 404 /customerrors/site2/404.html
    </Location>
</VirtualHost>

Edit:

To have the Proxy statements reside in the location blocks:

<VirtualHost 10.10.10.10:80>
    <Location /Site1>
        ErrorDocument 404 /customerrors/site1/404.html
    </Location>
    <Location /Site1/ServLet1>
        ProxyPass http://1.1.1.1/Site1/ServLet1
        ProxyPassReverse http://1.1.1.1/Site1/ServLet1
    </Location>

    <Location /Site2>
        ErrorDocument 404 /customerrors/site2/404.html
    </Location>    
    <Location /Site2/ServLet2>
        ProxyPass http://2.2.2.2/Site2/ServLet2
        ProxyPassReverse http://2.2.2.2/Site2/ServLet2
    </Location>
</VirtualHost>
share|improve this answer
    
It doesn't work. I added <Location /Site1> and when I browse to Site2 I still see the error for Site1. Also adding ProxyPass inside the Location tags gives me an error ProxyPass|ProxyPassMatch can not have a path when defined in a location. –  Mr Aleph Mar 9 '12 at 17:02
    
That's correct. If you're just proxying those specific servlets, then you'll want to define the blocks as <Location /Site2/ServLet2> and drop the /Site2/ServLet2 part from the Proxy commands. –  Shane Madden Mar 9 '12 at 17:11
    
what I want to do is that if the user browses to 10.10.10.10/Site1/ServLet1 then everything is fine, if he browses to 10.10.10.10/Site1/AnyOtherPage then display error. This needs to be done per page –  Mr Aleph Mar 9 '12 at 17:35
    
I still get ProxyPass|ProxyPassMatch can not have a path when defined in a location. I'm confused now, could write a little sample or modify the one in your answer? –  Mr Aleph Mar 9 '12 at 17:39
    
See comments on my question. I passes the request via the reverse proxy to http://1.1.1.1/Site1/ServLet1 but it doesn't show any error page –  Mr Aleph Mar 9 '12 at 18:06
show 3 more comments

Make it so that each vhost has it's own VirtualHost definition.

<VirtualHost 10.10.10.10:80>
    Servername site1.tld
    ProxyPass /Site1/ServLet1 http://1.1.1.1/Site1/ServLet1
    ProxyPassReverse /Site1/ServLet1 http://1.1.1.1//Site1/ServLet1
    ErrorDocument 404 /customerrors/site2/404.html
</VirtualHost>

<VirtualHost 10.10.10.10:80>
    ServerName site2.tld
    ProxyPass /Site2/ServLet2 http://2.2.2.2/Site2/ServLet2
    ProxyPassReverse /Site2/ServLet2 http://2.2.2.2/Site1/ServLet1
    ErrorDocument 404 /customerrors/site2/404.html
</VirtualHost>

You'll also need to ensure that you have a suitable NameVirtualHost definition.

share|improve this answer
    
I don't have a servername, they are all IP addresses –  Mr Aleph Mar 9 '12 at 17:53
1  
I think it would be simpler if you did the name based virtual hosting thing. –  Iain Mar 9 '12 at 17:54
    
such as? Can you modify your example to show me what you mean' –  Mr Aleph Mar 9 '12 at 17:56
    
@MrAleph It would mean using a different hostname for servlet; site1.example.com instead of example.com/site1/servlet1 - and I agree, that approach might simplify things future changes and maintenance. –  Shane Madden Mar 9 '12 at 19:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.