views:

258

answers:

3

I've set up a host with apache to serve static pages and to use Tomcat to serve my web application (See this question). The static pages are server from

"http://myhost.com"

and the dynamic (tomcat) pages are server from

"http://myhost.com/myapp"

The mod_proxy makes sure the "http://myhost.com/myapp" are forwarded to tomcat server running on "http://myhost.com:8080".

The problem is that now you get the standard Tomcat introduction page on "http://myhost.com/myapp" but if you click on a local link (e.g. 'Status') on the left, it generates an URL "http://myhost.com/manager/status" while it should generate: "http://myhost.com/myapp/manager/status"

(The same is true for webapps installed under tomcat)

What should be changed in my configuration (apache, tomcat?) to redirect my tomcat links to the right place?

A: 

Your URLs are mapped from:

http://myhost.com/myapp -> http://myhost.com:8080

This means that accessing the above URL will be mapped to the ROOT application in Tomcat. The ROOT application will generate pages that contain links from Tomcat's root context.

In other words, if you go to:

http://myhost.com:8080

you will get a page that contains links to

http://myhost.com:8080/manager/status

This link will work. However when that page is given back to a browser that requested it via Apache, the full URL then looks like: http://myhost.com/manager/status

I assume that you intend to deploy an application called 'myapp' to Tomcat? If that is the case the Tomcat URL for this app will be

http://myhost.com:8080/myapp

Which will also work be mapped correctly when accessed via Apache.

If you absolutely must access Tomcats root application in this way you'll have to rewrite the URLs it outputs in the pages it returns.

Joe
Actually in this set-up myapp now refers to the tomcat ROOT, which is ok. So a webapp should be under http://myhost.com/myapp/webapp.
Roalt
A: 

Have you set the ProxyPassReverse setting in your httpd.conf. This will overwrite the HTTP Header an you'll get to the correct request on the side of tomcat.

DrDol
I did the following:ProxyPass /myapp http://localhost:8080/ProxyPassReverse /myapp http://localhost:8080/But it does not work with the TOMCAT root folder. What I managed to do (as I only need to refer to my web application from myhost.com/mywebapp) is use the following ProxyPass commands:ProxyPass /mywebapp http://localhost:8080/mywebappProxyPassReverse /mywebapp http://localhost:8080/mywebappThis eventually helps me with my actual problem. However, why the tomcat still refers wrong for content that it server is still a mystery for me.
Roalt
IMHO you have to edit <default-uri> to mywebapp. The links are generated by your tomcat and if they are not like http://myhost.com/myapp/manager/status they fail.
DrDol
Do you know where you put the default-uri ?
Roalt
This infopage might be help: It's about url pattern and to set up them -> http://www2.roguewave.com/support/docs/leif/leif/html/bobcatug/7-3.html
DrDol
A: 

I've had the most success with mod_proxy_ajp. It requires mod_proxy, but works over ajp. Using it instead, your conf file looks similar

    ProxyPass / ajp://localhost:8009/

See my similar question and also the answer to this question. The only fault in mod_proxy_ajp that I've found is that if I need to restart tomcat I have to force an apache restart too.

lucas