<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rule of Tech &#187; webserver</title>
	<atom:link href="http://ruleoftech.com/journal/tag/webserver/feed" rel="self" type="application/rss+xml" />
	<link>http://ruleoftech.com</link>
	<description>Everything and nothing but still something about Tech</description>
	<lastBuildDate>Fri, 16 Jul 2010 16:27:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Redirect HTTP and HTTPS traffic to Tomcat&#8217;s ports</title>
		<link>http://ruleoftech.com/journal/redirecting-http-and-https-traffic-to-tomcats-ports</link>
		<comments>http://ruleoftech.com/journal/redirecting-http-and-https-traffic-to-tomcats-ports#comments</comments>
		<pubDate>Thu, 11 Jun 2009 18:47:17 +0000</pubDate>
		<dc:creator>Marko</dc:creator>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tomcat]]></category>
		<category><![CDATA[webserver]]></category>

		<guid isPermaLink="false">http://ruleoftech.wordpress.com/?p=38</guid>
		<description><![CDATA[Apache Tomcat likes with default settings to listen to requests on 8080 and 8443 ports but it is more enjoyable to use the more common 80 and 443 ports for HTTP and HTTPS traffic. This way the user don&#8217;t have to put those pesky port numbers after the address. Of course you could just tell [...]]]></description>
			<content:encoded><![CDATA[<p>Apache Tomcat likes with default settings to listen to requests on 8080 and 8443 ports but it is more enjoyable to use the more common 80 and 443 ports for HTTP and HTTPS traffic. This way the user don&#8217;t have to put those pesky port numbers after the address. Of course you could just tell Tomcat to listen to those ports but it has some negative sides: hassle with the startup and running Tomcat as root.</p>
<p>Luckily it is easy to tell the system to redirect the traffic from some port to other. Just define some new xinetd services in <em>/etc/xinetd.d/tomcat</em>.</p>
<pre>
# vim /etc/xinetd.d/tomcat

# Redirects any requests on port 80 to port 8080 (where Tomcat is listening)
service tomcat-http
{
        disable                 = no
        flags                   = REUSE
        wait                    = no
        user                    = root
        socket_type         = stream
        protocol                = tcp
        port                    = 80
        redirect                = localhost 8080
        log_on_success  -= PID HOST DURATION EXIT

        #per_source = UNLIMITED
        #instances = UNLIMITED
}

# Redirects any requests on port 443 to port 8443 (where Tomcat is listening)
service tomcat-https
{
        disable                 = no
        flags                   = REUSE
        wait                    = no
        user                    = root
        socket_type         = stream
        protocol                = tcp
        port                    = 443
        redirect                = localhost 8443
        log_on_success  -= PID HOST DURATION EXIT

        #per_source = UNLIMITED
        #instances = UNLIMITED
}
</pre>
<p>(via <a href="http://www.ibm.com/developerworks/java/library/l-secjav.html#h5">Securing Linux for Java services: The port dilemma</a>)</p>
<p>Xinetd puts a connection limit per source IP, by default and this causes the service to become unresponsive when there are dozens of queries a second. You see the following kind of line in your messages log file: &#8220;xinetd[2049]: FAIL: tomcat-https per_source_limit from=123.456.789.123&#8243;. To correct this, uncomment the per_source and instances lines in your xinet.d file and restart it.</p>
<p>Also add those xinetd services to <em>/etc/services</em>.</p>
<pre>
# vim /etc/services
http        80/tcp     www www-http tomcat-http # WorldWideWeb http
http        80/udp     www www-http tomcat-http # WorldWideWeb HTTP
http        443/tcp    tomcat-https # WorldWideWeb HTTPS
http        443/udp    tomcat-https # WorldWideWeb HTTPS
</pre>
<p>And now just restart the xinetd and admire how your traffic is redirected to Tomcat&#8217;s ports.</p>
<pre>
# service xinetd restart
</pre>
<p><strong>Force everything to transmit through HTTPS</strong><br />
If you also want to redirect all HTTP traffic to HTTPS you can add the following section to you Tomcat <em>web.xml</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-resource-collection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-resource-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Protected Context<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-resource-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-resource-collection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- auth-constraint goes here if you requre authentication --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;user-data-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transport-guarantee<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>CONFIDENTIAL<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/transport-guarantee<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/user-data-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>If you are using this redirection of all traffic to HTTPS with JIRA and want to attachments working also with Internet Explorer then you must add the following to your <em>jira.xml</em> (f. ex. /opt/tomcat/conf/Catalina/localhost/jira.xml). This is a Internet Explorer bug, for more information see <a href="http://jira.atlassian.com/browse/JRA-8179">http://jira.atlassian.com/browse/JRA-8179</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Context</span> ...<span style="color: #000000; font-weight: bold;">&gt;</span></span>
...
<span style="color: #808080; font-style: italic;">&lt;!-- for IE bug, see http://jira.atlassian.com/browse/JRA-8179--&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Valve</span> <span style="color: #000066;">className</span>=<span style="color: #ff0000;">&quot;org.apache.catalina.authenticator.NonLoginAuthenticator&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">disableProxyCaching</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Context<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2  class="related_post_title">Related journal entries</h2><ul class="related_post"><li><a href="http://ruleoftech.com/journal/installing-apache-tomcat-6-on-centos" title="Installing Apache Tomcat 6 on CentOS">Installing Apache Tomcat 6 on CentOS</a></li><li><a href="http://ruleoftech.com/journal/installing-sun-jdk-1-6-on-centos" title="Installing Sun JDK 1.6 on CentOS">Installing Sun JDK 1.6 on CentOS</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://ruleoftech.com/journal/redirecting-http-and-https-traffic-to-tomcats-ports/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
