How to run WordPress and Java web app running on Tomcat on the same server?
- by Chantz
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.
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.
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.