Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
Thank you! I have a standard Cent OS linux VPS. cPanel is taking care of my apache configuration. Where should I look for the file to try what you suggested here? Also, I tried setting up ajp and couldn't get it working. Every way I tried to install the components gave me some error. What is http proxy? Maybe I should give that a try. –  Thorn Mar 21 '12 at 19:34
    
Hey Thorn, it takes a while to get it setup and running correctly. If you use mod_proxy w/ajp, you have to setup the tomcat connector on tomcat's server.xml. You have to enable port 8009 for AJP protocol. If you don't get the details right, it definitely won't work. You need to find your config for Apached http and tomcat. Post them here without the private information. Look for the files in apache/conf/httpd.conf and tomcat/conf/server.xml. mod_proxy supports both ajp and http, see doc: httpd.apache.org/docs/2.0/mod/mod_proxy.html. –  Jason Huntley Mar 21 '12 at 19:47
    
You could also check the cPanel doc, maybe it might tell you where to find the config files: docs.cpanel.net/twiki/bin/view/EasyApache3/WebHome I'm not very familiar with cPanel. –  Jason Huntley Mar 21 '12 at 19:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.