Question

Using an Apache virtualhost and mod_proxy I want to access a java application (myapp) available in a jetty instance on port 8080.

With ProxyPass / localhost:8080/ on my apache virtualhost configuration I can access the application running in jetty with www.mydomain.com/myapp but I want the application to be accessed from www.mydomain.com.

Trying with ProxyPass / localhost:8080/myapp The application cannot be found because the request becomes www.mydomain.com/myappmyapp/.

Then tried with:

<Location />
        ProxyPass localhost:8080/myapp/
        SetEnv force-proxy-request-1.0 1
        SetEnv proxy-nokeepalive 1
</Location>

I can access the application but just for the first request. Subsequent requests become www.mydomain.com/myappmyapp/

After reading many times wiki.eclipse.org/Jetty/Tutorial/Apache and the apache mod_proxy docs the only way I managed to use the application properly from www.mydomain.com is with the following configuration:

<Location /myapp/>
        ProxyPass localhost:8080/myapp/
        SetEnv force-proxy-request-1.0 1
        SetEnv proxy-nokeepalive 1
</Location>

<Location />
        ProxyPass localhost:8080/myapp/
        SetEnv force-proxy-request-1.0 1
        SetEnv proxy-nokeepalive 1
</Location>

so the request is forwarded to the jetty application in both cases.

I am quite new to apache and jetty and I am pretty sure there is a better and more elegant way of achieving the same result. In fact apache complains saying:

[warn] worker localhost:8080/myapp/ already used by another worker
Was it helpful?

Solution

The problem is that when you deploy your application in jetty with the context path /myapp, it will generate all links accordingly. Apache mod_proxy does all the rewriting at the HTTP level (headers) and won't do anything with the response body, keeping it as it is.

If you don't mind the /myapp sticking around, you can turn mod_rewrite on and include following two lines in your Location block:

RewriteEngine on
RewriteRule ^/myapp/(.*)$ /$1 [P]

If you would like to get rid of /myapp for good, then the only option left (assuming you don't want to waste CPU power on mod_proxy_html) is to configure virtual hosts, and deploy applications on virtual hosts with context path of /.

OTHER TIPS

If you want your webapp to be accessible at the root of your site, what you need is to deploy the web application into the root of container. Usually, this is done by calling the war file ROOT.war instead of myapp.war (although this ultimately depend on the configuration of your Jetty deployer, which may be more complex than the default).

Yes it works from the jetty root, but I would like to have more than one application running. The configuration for myapp is under jetty's contexts folder:

<Configure class="org.mortbay.jetty.webapp.WebAppContext">
  <Set name="contextPath">/mvc-showcase</Set>
  <Set name="war"><SystemProperty name="jetty.home"/>/webapps/mvc-showcase.war</Set>
</Configure>

my jetty version is 6.1.22

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top