English 中文(简体)
Tomcat serving URLs wrong with mod_proxy and apache
原标题:

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?

最佳回答

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.

问题回答

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.

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.





相关问题
Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

Multiple Sites with common files

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images. What ...

http server validation

I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing ...

热门标签