How to run WordPress and Java web app running on Tomcat on the same server?

Posted by Chantz on Pro Webmasters See other posts from Pro Webmasters or by Chantz
Published on 2014-06-12T04:39:26Z Indexed on 2014/06/12 9:42 UTC
Read the original article Hit count: 181

I have to run a WordPress site served via Apache2 & Java-based webapp using Tomcat on the same server.

When users come to example.com or example.com/public-pages they need to served from WordPress but when they come to example.com/private-pages they need to be served from the Tomcat.

I have asked this question on serverfault where they suggested using different port, different IP & sub-domain.

I want to go for different port solution since it will mean I need to buy only one SSL certificate.

I tried doing the reverse proxy method by having the following in my default-ssl.conf

    <VirtualHost _default_:443>
            ServerAdmin webmaster@localhost
            ServerName localhost:443

            DocumentRoot /var/www

            <Directory /var/www>
            #For Wordpress
                    Options FollowSymLinks
                    AllowOverride All
            </Directory>

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

            ProxyRequests           Off
            ProxyPass               /private-pages       ajp://localhost:8009/
            ProxyPassReverse        /private-pages       ajp://localhost:8009/


            SSLEngine on
            SSLProxyEngine On


            SSLCertificateFile      /etc/apache2/ssl/apache.crt
            SSLCertificateKeyFile /etc/apache2/ssl/apache.key

    </VirtualHost> 

As you have noticed I am using mod_proxy_ajp in Apache2 for this. And that my Tomcat is listening to port 8009 and then serving content. So now when I go to example.com/private-pages I am seeing the content from my Tomcat. But 2 issues are happening.

  1. All my static resources are getting 404-ed, so none of my images, CSS, js are getting loaded. I see that the browser is requesting for the resources using URL example.com/css/* This will clearly not work because it translates to example.com:80/css/* instead of example.com:8009/css/* & there are no such resources in the WordPress directory.
  2. If I go to example.com/private-pages/abcd I am somehow kicked to the WordPress site (which obviously displays a 404 page).

I can understand why #1 is happening but have no clue why the #2 is happening. Regardless, if there is another clean solution for resolving this, I would appreciate y'alls help.

© Pro Webmasters or respective owner

Related posts about redirects

Related posts about apache