<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: How do I force HTTPS in Tomcat (through Apache and mod_jk)?</title>
	<link>http://ask.metafilter.com/53101/How-do-I-force-HTTPS-in-Tomcat-through-Apache-and-modjk/</link>
	<description>Comments on Ask MetaFilter post How do I force HTTPS in Tomcat (through Apache and mod_jk)?</description>
	<pubDate>Wed, 13 Dec 2006 16:16:17 -0800</pubDate>
	<lastBuildDate>Wed, 13 Dec 2006 16:16:17 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: How do I force HTTPS in Tomcat (through Apache and mod_jk)?</title>
		<link>http://ask.metafilter.com/53101/How-do-I-force-HTTPS-in-Tomcat-through-Apache-and-modjk</link>	
		<description>I&apos;m at my wit&apos;s end. I&apos;ve been trying to configure tomcat (through apache 2 using mod_jk) to automatically re-direct all traffic to HTTPS from HTTP. More boring technical details to follow. &lt;br /&gt;&lt;br /&gt; Specifically, I&apos;m trying to get &lt;a href=&quot;http://www.ja-sig.org/products/cas/&quot;&gt;CAS&lt;/a&gt; working. Tomcat is successfully serving-up the pages over HTTP and HTTPS and the application is working as expected. However, since this particular servlet handles user authentication I would like Tomcat to force HTTPS for all requests.&lt;br&gt;
&lt;br&gt;
I have tried using isSecure() through JSP to redirect users but it simply puts the requests into an endless loop. I have tried the &lt;a href=&quot;http://www.jguru.com/faq/view.jsp?EID=748030&quot;&gt;following configuration&lt;/a&gt; in the web.xml file (see Lukas Bradleys&apos; answer) and it does force a redirect, but it uses the server hostname as the URL and not the proxied URL to the server (which means it doesn&apos;t work externally).&lt;br&gt;
&lt;br&gt;
I&apos;ve tried changing the hostname on the server but it continues to use the initial hostname which leads me to believe that this value is somewhere in the Tomcat configuration, but I cannot locate it.&lt;br&gt;
&lt;br&gt;
So, is there an easier way to do this? Or, does anyone know where to look to modify that hostname to use the URL for the proxied site? Any assistance would be appreciated.</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2006:site.53101</guid>
		<pubDate>Wed, 13 Dec 2006 15:56:41 -0800</pubDate>
		<dc:creator>purephase</dc:creator>
		
			<category>web</category>
		
			<category>tomcat</category>
		
			<category>CAS</category>
		
			<category>https</category>
		
			<category>java</category>
		
			<category>servlet</category>
		
			<category>security</category>
		
	</item> <item>
		<title>By: boaz</title>
		<link>http://ask.metafilter.com/53101/How-do-I-force-HTTPS-in-Tomcat-through-Apache-and-modjk#800582</link>	
		<description>Mod_rewrite will handle this lickety-split.&lt;br&gt;
&lt;br&gt;
&lt;code&gt;RewriteEngine On&lt;br&gt;
RewriteCond %{HTTPS} off&lt;br&gt;
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1  [L,R]&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
You might want to test that first.  You can use a second rule to limit it to certain urls, like &lt;code&gt;RewriteCond %{REQUEST_URI} /mydir/(.*)&lt;/code&gt;.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.53101-800582</guid>
		<pubDate>Wed, 13 Dec 2006 16:16:17 -0800</pubDate>
		<dc:creator>boaz</dc:creator>
	</item><item>
		<title>By: SirStan</title>
		<link>http://ask.metafilter.com/53101/How-do-I-force-HTTPS-in-Tomcat-through-Apache-and-modjk#800586</link>	
		<description>boaz has it covered.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.53101-800586</guid>
		<pubDate>Wed, 13 Dec 2006 16:19:39 -0800</pubDate>
		<dc:creator>SirStan</dc:creator>
	</item><item>
		<title>By: majick</title>
		<link>http://ask.metafilter.com/53101/How-do-I-force-HTTPS-in-Tomcat-through-Apache-and-modjk#800626</link>	
		<description>No need to get fancy with mod_rewrite.  Just use the &lt;a href=&quot;http://www.apache-ssl.org/docs.html#SSLRequireSSL&quot;&gt;SSLRequireSSL&lt;/a&gt; directive.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.53101-800626</guid>
		<pubDate>Wed, 13 Dec 2006 17:03:26 -0800</pubDate>
		<dc:creator>majick</dc:creator>
	</item><item>
		<title>By: drstein</title>
		<link>http://ask.metafilter.com/53101/How-do-I-force-HTTPS-in-Tomcat-through-Apache-and-modjk#800636</link>	
		<description>I think you can also run it through the ProxyPass directive.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.53101-800636</guid>
		<pubDate>Wed, 13 Dec 2006 17:21:51 -0800</pubDate>
		<dc:creator>drstein</dc:creator>
	</item><item>
		<title>By: purephase</title>
		<link>http://ask.metafilter.com/53101/How-do-I-force-HTTPS-in-Tomcat-through-Apache-and-modjk#800637</link>	
		<description>Using re-write rules in the virtual host settings in Apache cause extremely weird reactions. .htaccess files also do not seem to have any effect at all.&lt;br&gt;
&lt;br&gt;
I haven&apos;t tried SSLRequireSSL so I&apos;ve sent that off to my server admin to see if he can give it a shot (I don&apos;t have access to the apache conf, just the servlets).</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.53101-800637</guid>
		<pubDate>Wed, 13 Dec 2006 17:22:10 -0800</pubDate>
		<dc:creator>purephase</dc:creator>
	</item><item>
		<title>By: SirStan</title>
		<link>http://ask.metafilter.com/53101/How-do-I-force-HTTPS-in-Tomcat-through-Apache-and-modjk#800662</link>	
		<description>I use mod_rewrite on ~40 vhosts no problem.  Not sure what  &apos;wierd reactions&apos; you are talking about.  &lt;br&gt;
&lt;br&gt;
This sounds like a case of a really poorly configured server.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.53101-800662</guid>
		<pubDate>Wed, 13 Dec 2006 17:49:00 -0800</pubDate>
		<dc:creator>SirStan</dc:creator>
	</item><item>
		<title>By: purephase</title>
		<link>http://ask.metafilter.com/53101/How-do-I-force-HTTPS-in-Tomcat-through-Apache-and-modjk#800677</link>	
		<description>Are they passing servlets through Tomcat? I have no issue with mod_rewrite through Apache, it&apos;s only when it&apos;s done with mod_jk and Tomcat that the same rules do not work as I intended.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.53101-800677</guid>
		<pubDate>Wed, 13 Dec 2006 18:05:34 -0800</pubDate>
		<dc:creator>purephase</dc:creator>
	</item><item>
		<title>By: sbutler</title>
		<link>http://ask.metafilter.com/53101/How-do-I-force-HTTPS-in-Tomcat-through-Apache-and-modjk#800779</link>	
		<description>How do you have your connectors configured? You should have two: one for the unsecured traffice, and another for the secured. Here&apos;s an example of a server.xml (this is all from memory... untested):&lt;br&gt;
&lt;br&gt;
&amp;lt;!-- Unsecured connector --&amp;gt;&lt;br&gt;
&amp;lt;Connector protocol=&quot;AJP/1.3&quot; redirectPort=&quot;443&quot; scheme=&quot;http&quot; secure=&quot;false&quot; address=&quot;127.0.0.1&quot; port=&quot;8008&quot; /&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;!-- Secured connector --&amp;gt;&lt;br&gt;
&amp;lt;Connector protocol=&quot;AJP/1.3&quot; redirectPort=&quot;443&quot; scheme=&quot;https&quot; secure=&quot;true&quot; address=&quot;127.0.0.1&quot; port=&quot;8009&quot; /&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Then, when you configure the workers.properties, you need two workers:&lt;br&gt;
&lt;br&gt;
worker.list=ajp13unsecure, ajp13secure&lt;br&gt;
&lt;br&gt;
worker.ajp13unsecure.type=ajp13&lt;br&gt;
worker.ajp13unsecure.host=localhost&lt;br&gt;
worker.ajp13unsecure.port=8008&lt;br&gt;
&lt;br&gt;
worker.ajp13secure.type=ajp13&lt;br&gt;
worker.ajp13secure.host=localhost&lt;br&gt;
worker.ajp13secure.port=8009&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Finally, inside your apache vhost config files, you&apos;ll have something like this:&lt;br&gt;
&lt;br&gt;
&amp;lt;VirtualHost *:80&amp;gt;&lt;br&gt;
# ...&lt;br&gt;
JkMount /*.jsp ajp13unsecure&lt;br&gt;
JkMount /servlet/* ajp13unsecure&lt;br&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&amp;lt;VirtualHost *:443&amp;gt;&lt;br&gt;
# ...&lt;br&gt;
JkMount /*.jsp ajp13secure&lt;br&gt;
JkMount /servlet/* ajp13secure&lt;br&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
So basically, you have to setup two parallel configurations: one secured, one unsecured. Then Tomcat will know how to forward requests, and when a request is secure or not.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.53101-800779</guid>
		<pubDate>Wed, 13 Dec 2006 20:21:07 -0800</pubDate>
		<dc:creator>sbutler</dc:creator>
	</item><item>
		<title>By: purephase</title>
		<link>http://ask.metafilter.com/53101/How-do-I-force-HTTPS-in-Tomcat-through-Apache-and-modjk#800789</link>	
		<description>Is the workers.properties file integral to this? My server admin disagrees (and he knows this stuff much better than I do). Does Tomcat use the values in that file to determine the host information when handling the CONFIDENTIAL secure transport?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.53101-800789</guid>
		<pubDate>Wed, 13 Dec 2006 20:37:34 -0800</pubDate>
		<dc:creator>purephase</dc:creator>
	</item><item>
		<title>By: sbutler</title>
		<link>http://ask.metafilter.com/53101/How-do-I-force-HTTPS-in-Tomcat-through-Apache-and-modjk#800793</link>	
		<description>Yes. If you don&apos;t specify the other connector in the workers.properties file, then how is Apache and mod_jk supposed to know it exists?&lt;br&gt;
&lt;br&gt;
The only way that Tomcat knows a connection is secure is because you marked it secure in the Connector element. So if you want to handle both secure and unsecure traffic, you need two connectors.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.53101-800793</guid>
		<pubDate>Wed, 13 Dec 2006 20:40:08 -0800</pubDate>
		<dc:creator>sbutler</dc:creator>
	</item><item>
		<title>By: sbutler</title>
		<link>http://ask.metafilter.com/53101/How-do-I-force-HTTPS-in-Tomcat-through-Apache-and-modjk#800810</link>	
		<description>What I should say is that this method has worked for me in the past. Looking through the &lt;a href=&quot;http://tomcat.apache.org/connectors-doc/config/apache.html&quot;&gt;mod_jk&lt;/a&gt; docs a little closer, it appears there may be other ways that don&apos;t require two connectors. Specifically, look at JkExtractSSL. Perhaps that&apos;s what your admin is thinking of.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.53101-800810</guid>
		<pubDate>Wed, 13 Dec 2006 21:01:41 -0800</pubDate>
		<dc:creator>sbutler</dc:creator>
	</item><item>
		<title>By: purephase</title>
		<link>http://ask.metafilter.com/53101/How-do-I-force-HTTPS-in-Tomcat-through-Apache-and-modjk#800813</link>	
		<description>The server.xml file has the two connectors specified, and both the 80 and 443 vhosts are specified in the httpd and ssl conf files.&lt;br&gt;
&lt;br&gt;
There is no workers.properties file at the moment but I&apos;ll get him to look into that tomorrow. The SSL redirect works in Tomcat when I specify the CONFIDENTIAL secure-transport setting, it just doesn&apos;t re-direct to the correct URL (it uses the server hostname, not the proxied URL). Maybe specifying the .host values in the workers.properties will ensure that it uses the URL instead of the hostname.&lt;br&gt;
&lt;br&gt;
The ServerName value in the vhosts files do not seem to have any effect.&lt;br&gt;
&lt;br&gt;
Thanks for the help.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.53101-800813</guid>
		<pubDate>Wed, 13 Dec 2006 21:05:14 -0800</pubDate>
		<dc:creator>purephase</dc:creator>
	</item><item>
		<title>By: sbutler</title>
		<link>http://ask.metafilter.com/53101/How-do-I-force-HTTPS-in-Tomcat-through-Apache-and-modjk#800817</link>	
		<description>There&apos;re proxyName/proxyPort attributes for the &lt;a href=&quot;http://tomcat.apache.org/tomcat-5.5-doc/config/ajp.html&quot;&gt;Connector&lt;/a&gt;. I don&apos;t really know much about that, though.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.53101-800817</guid>
		<pubDate>Wed, 13 Dec 2006 21:11:52 -0800</pubDate>
		<dc:creator>sbutler</dc:creator>
	</item><item>
		<title>By: purephase</title>
		<link>http://ask.metafilter.com/53101/How-do-I-force-HTTPS-in-Tomcat-through-Apache-and-modjk#801859</link>	
		<description>I think you might be on to something. Thanks for the links and explanation. I think the missing link here is the workers.properties file so we need to start there. The proxyPort and proxyName attributes, as well as properly defined defaultHost attributes in the server.xml file (and associated host and vhost settings in workers.properties and httpd.conf) are the key making all of this fit together.&lt;br&gt;
&lt;br&gt;
I&apos;ll post more tomorrow if there is any success/failures etc.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.53101-801859</guid>
		<pubDate>Thu, 14 Dec 2006 18:51:57 -0800</pubDate>
		<dc:creator>purephase</dc:creator>
	</item><item>
		<title>By: purephase</title>
		<link>http://ask.metafilter.com/53101/How-do-I-force-HTTPS-in-Tomcat-through-Apache-and-modjk#802373</link>	
		<description>No luck. I&apos;ve posted the question to the CAS listserv to see if anyone has any ideas there.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.53101-802373</guid>
		<pubDate>Fri, 15 Dec 2006 09:15:42 -0800</pubDate>
		<dc:creator>purephase</dc:creator>
	</item>
	</channel>
</rss>
