1
  1. My old way using mod_jk in apache and configure virtual host in tomcat In the JSP file, I refer to CSS as below

    /<%=request.getContextPath()%>/css/styles.css

while the home link is set to

/<%=request.getContextPath()%>/

so this worked fine when I use mod_jk in apache to work with tomcat using ajp;

  1. When I try to configure reverse proxy as below

ProxyPass / http://localhost:800/mywebapp

ProxyPassReverse / http://localhost:800/mywebapp

the home page can be retrieved fine but the css request becomes http://mydomain.com/mywebapp/mywebapp/css/style.css so the css file can not be retrieved correctly;

  1. I think one possible way is to always use relative path like ./style.css or ../style.css a. since header/footer are shared, and the home page is in a different level with detail page, it's inconvenient to use relative path because they're at a different level b. still, I think the home link will have to be /<%=request.getContextPath()%>/

so I wonder what's the way to set contextroot fine in java web and also work fine with reverse proxy?

thx a lot

Santosh
  • 17,667
  • 4
  • 54
  • 79
hetaoblog
  • 1,990
  • 5
  • 26
  • 34

1 Answers1

0

As I know your application server (Tomcat) isn't able to be aware of a reverse proxy presence. Generally speaking, it can be contacted through any number of reverse proxies or directly by browsers. A network configuration is usually used to limit this, not HTTP or Java.

So, you must accurately rely on relative URLs to make your application work well.

When I have to deal with reverse proxy presence (almost always due to SSO architectures), I embed a "junction" configuration string item (the portion of the URL used in the proxy to map the application) and use it in the only places where I need to build an absolute URL.

Andrea Colleoni
  • 5,919
  • 3
  • 30
  • 49
  • hi, thx for reply; questions: 1. how do you specify your links to css and home link? 2. how do you specify reverse proxy setting in apache config? thx. – hetaoblog Jan 04 '12 at 02:47
  • I usually add an Helper class with a static method that returns me a config param, that I put in a .properties file, so the reference to you css could be: <%=UrlHelper.getBasePath()%>/css/styles.css and in the getBasePath method you can read properties, environment, db, and so on. – Andrea Colleoni Jan 04 '12 at 08:26
  • do you set this in your reverse proxy config? ProxyPass / http://localhost:800/mywebapp, – hetaoblog Jan 05 '12 at 02:53