[GIS] Cannot ProxyPass to geoserver if source name is anything other than /geoserver

apachegeoserverPROXYtomcat

I have been using apache's ProxyPass command to proxy

 http://localhost:8080/geoserver/ 

as follows:

    ProxyPass /geoserver http://localhost:8082/geoserver
    ProxyPassReverse /geoserver http://localhost:8082/geoserver

This works fine until I change the source path to

    ProxyPass /geoserver1 http://localhost:8082/geoserver
    ProxyPassReverse /geoserver1 http://localhost:8082/geoserver

When changed to above, If I go to

    http://localhost/geoserver1

in a browser, it will be redirected to

 http://localhost/geoserver 

automatically, without the port number. And then this gives an error of 404, address not found.

This happens if the source is anything other than /geoserver and the destination is

http://localhost:8082/geoserver

(I suspect this has something to do with the automatic redirect from

http://localhost:8082/geoserver

to

http://localhost:8082/geoserver/web

But I am not sure whether this is the case.

How do I fix it?

This is with GeoServer 2.5 in osgeo live 8

Best Answer

The issue is to do with the Tomcat settings and not with any settings of GeoServer.

Note the Tomcat docs tell us:

It should be noted that it is not recommended to use a reverse proxy to change the context path because of the multiple issues it creates.

So if you want to run GeoServer under a different name you might consider changing the name of the GeoServer war file deployed, or changing the name in a context file, but if you really want to use the proxy settings the following worked for me:

In httpd.conf

ProxyRequests Off
ProxyPreserveHost On

<Proxy /gs/>
    Require all granted
</Proxy>
ProxyPass /gs/ ajp://127.0.0.1:8009/geoserv/
ProxyPassReverse /gs/ ajp://127.0.0.1:8009/geoserv/

In server.xml

<Context 
    path="/geoserv"
    docBase="C:\apps\geoserver\gs_2.9x"
    crossContext="true" 
    reloadable="false"
    <!-- having useRelativeRedirects set as true is the important bit! -->
    useRelativeRedirects="true"
/>