1

I'm implementing a JSF2/RichFaces 4 web application running under Tomcat 7. I developed it under Eclipse using MyEclipse with Tomcat 7, everything works fine. When I deploy the application to the full production environment, the resource library images/css/js files get 404 from Apache. The production environment is Apache 2 with SSL and mod_proxy front-ending Tomcat 7. I'm suspecting the proxy setup is wrong and that, while the tomcat webapp runs, the Apache GET requests aren't being proxied properly, but I don't think I know enough to understand why.

Starting from the top, here's my apache virtual host with proxies (note *:443 for ssh):

NameVirtualHost *:443

<VirtualHost *:443>
    ServerName testapp.xxx.org

    SSLEngine on
    SSLProxyEngine on
    SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
    SSLCertificateFile /etc/pki/tls/certs/testapp.xxx.org.crt
    SSLCertificateKeyFile /etc/pki/tls/private/testapp.xxx.org.key

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    # Proxy everything to tomcat.
    ProxyPass         /      http://localhost:8080/testapp/
    ProxyPassReverse  /      http://localhost:8080/testapp/
</VirtualHost>

When I go to https://testapp.xxx.org, the application starts and displays the JSF but with no CSS, no js, and no images. The HTML for one such image resource looks like this, which is correct (same under Eclipse):

<img src="/testapp/javax.faces.resource/images/tairlogo.png.xhtml?ln=default" alt="TAIR web site" />

which should be starting at the webapp context root and looking for the resource library. The corresponding Apache access log GET is here:

"GET /testapp/javax.faces.resource/images/tairlogo.png.xhtml?ln=default HTTP/1.1" 404 12500

The actual JSF code for this image is:

  <h:outputLink value="http://www.arabidopsis.org">
    <h:graphicImage library="default" name="images/tairlogo.png"
      alt="TAIR web site"></h:graphicImage>
  </h:outputLink>
Bob Muller
  • 55
  • 8

1 Answers1

0

I think the problem is that your reverse proxy rule is assuming that the context name (testapp) is not present in the URL, while in the HTML you are assuming it is present (as in the src attribute of your img tag). You should either remove the context name in both the path and the target URL to proxy everything to Tomcat, e.g.:

ProxyPass         /      http://localhost:8080/
ProxyPassReverse  /      http://localhost:8080/

Or keep it in both to only proxy that webapp to Tomcat:

ProxyPass         /testapp/      http://localhost:8080/testapp/
ProxyPassReverse  /testapp/      http://localhost:8080/testapp/

This will make your webapp available at https://testapp.xxx.org/testapp/. If you don't want the context name part in the URL, you can deploy the webapp in the Tomcat root.

Community
  • 1
  • 1
David Levesque
  • 22,181
  • 8
  • 67
  • 82
  • I changed my app to be ROOT.war (removed the ROOT directory under tomcat/webapps) to make it the default webapp. I changed my reverse proxy to the first choice, no "testapp". Everything worked fine. – Bob Muller Sep 07 '13 at 20:10
  • I'm curious, though: what if you have 10 web apps running under tomcat and 10 different subdomains to run them, how do you do that? In JBoss you do it with virtual hosts defined in jboss-web.xml. Is there something similar with tomcat for defining virtual hosts? Or do you just have to live with the /webapp syntax in the URL? – Bob Muller Sep 07 '13 at 20:12
  • I've never had to implement such a setup, but I believe you would have to define virtual hosts in both Tomcat and Apache, with a ProxyPass rule for each of them. See http://tomcat.apache.org/tomcat-7.0-doc/virtual-hosting-howto.html – David Levesque Sep 08 '13 at 21:06