Tomcat – Running Tomcat 7 and Apache 2 on the same server

apache-2.2tomcat

Part of my site needs to run over HTTPS and I'm creating a sub-domain for that part. I have apache httpd 2 AND Tomcat 7 running on the same server with the same IP, Apache is on port 80 of course, while Tomcat is running on port 8080. Right now I am doing domain forwarding for requests that need to run off tomcat. For example, mathteamhosting.com/mathApp can forward to mathteamhosting.com:8080/mathApp.

I would like to have Tomcat handle the https requests for that subdomain. I don't think this forwarding technique can work in this case. How do I set that up so that Tomcat receives the requests on port 443 while apache handles port 80.

To be more specific:
http://proctinator.com ==> request goes to Apache web server
https://private.proctinator.com ==> request goes to Apache web server

Best Answer

I would like to have Tomcat handle the https requests for that subdomain. I don't think this forwarding technique can work in this case. How do I set that up so that Tomcat receives the requests on port 443 while apache handles port 80.

Actually, you can configure virtual hosts to forward all types of requests, including 443. Just setup two virtual hosts for the same server, but forward by port. Port 80 can go to your webhost and 443 to your tomcate via ajp or http proxy. Example:

NameVirtualHost *:80
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName proctinator.com 

        RewriteEngine On
        RewriteCond %{HTTPS} !=on
        RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>

NameVirtualHost *:443
<VirtualHost *:443>
SSLEngine On
ServerName private.proctinator.com

ProxyRequests off
ProxyPreserveHost On

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

ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/

<Location />
    Order allow,deny
    Allow from all
</Location>
</VirtualHost>

You'll have to tinker around with the config settings a little, but this should provide the setup you describe.

Related Topic