<?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>dominikdorn.com &#187; apache</title>
	<atom:link href="http://dominikdorn.com/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://dominikdorn.com</link>
	<description>shit happens ;)</description>
	<lastBuildDate>Tue, 03 Jan 2012 19:47:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Tomcat/Glassfish/Jetty on Port 80 with IPTables</title>
		<link>http://dominikdorn.com/2010/04/tomcat-glassfish-jetty-port-80-iptables-nat/</link>
		<comments>http://dominikdorn.com/2010/04/tomcat-glassfish-jetty-port-80-iptables-nat/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 20:24:19 +0000</pubDate>
		<dc:creator>Dominik Dorn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[Glassfish]]></category>
		<category><![CDATA[jboss as]]></category>
		<category><![CDATA[jetty]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://dominikdorn.com/?p=260</guid>
		<description><![CDATA[If you &#8211; like me &#8211; have the problem, that you need to run Tomcat or Glassfish or any other Java Webserver on Port 80, this might come handy for you: The problem: Tomcat, Jetty, Glassfish, JBoss AS etc. .. they all run on unprivileged ports &#62; 1024, defaulting to 8080. If you want to [...]]]></description>
			<content:encoded><![CDATA[<p>If you &#8211; like me &#8211; have the problem, that you need to run Tomcat or Glassfish or any other Java Webserver on Port 80, this might come handy for you:</p>
<p>The problem:<br />
Tomcat, Jetty, Glassfish, JBoss AS etc. .. they all run on unprivileged ports &gt; 1024, defaulting to 8080.</p>
<p>If you want to run them on port 80, you have several choices:<br />
- front them with Apache<br />
- front them with Squid<br />
- use some tools like authbind, etc.<br />
- use IPTables magic (which we will describe here)</p>
<p>Primitive IPTables solution:<br />
This solution comes from the blog entry &#8221; <a href="http://rifers.org/wiki/display/RIFE/Installing+Tomcat+on+port+80+with+iptables">Installing Tomcat on port 80 with iptables</a> &#8221;<br />
You have to compile NAT support into your kernel and use an iptables rule like this one</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">iptables <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-I</span> PREROUTING <span style="color: #660033;">--src</span> <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span> <span style="color: #660033;">--dst</span> <span style="color: #007800;">$yourip</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> REDIRECT <span style="color: #660033;">--to-ports</span> <span style="color: #000000;">8080</span></pre></div></div>

<p>which redirects all incoming traffic on port 80 on $yourip (e.g. 74.125.39.99) to port 8080 on the local machine.<br />
If your webserver listens only to 127.0.0.1 this is all you need to be save.</p>
<p>However, I have a bit a different setup:</p>
<p>- Two networks with different providers (4mbit e.g. 74.125.39.99, 12mbit e.g. 98.137.149.56 )<br />
- Two servers, one of them quite small powered (pentium4 on the 4mbit line), the other quite strong (dual quad core 2ghz on the 12mbit line)<br />
- Glassfish on the strong server<br />
- DNS load balancing for the domain<br />
- both servers should map to the same glassfish instance.<br />
- the servers are connected through a direct link with private IP-addresses (10.x.x.x range)<br />
- Glassfish binds only to the private IP-Address of the strong server, meaning 10.0.100.10:8080<br />
- both 74.125.39.99:80 and 98.137.149.56:80 should redirect the traffic to 10.0.100.10:8080</p>
<p>Here&#8217;s how I&#8217;ve done it (I got some inspiration from this <a href="http://www.linuxquestions.org/questions/linux-security-4/iptables-nat-port-forwarding-rule-set-492758/">linux questions forum entry</a>):</p>
<p>On the &#8220;strong&#8221; server</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#this forwards traffic to the internal ip</span>
iptables <span style="color: #660033;">-A</span> PREROUTING <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-d</span> 74.125.39.99<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> DNAT <span style="color: #660033;">--to</span> 10.0.100.10:<span style="color: #000000;">8080</span>
<span style="color: #666666; font-style: italic;">#this allows traffic on the external interface on port 80</span>
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-d</span> 74.125.39.99<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #666666; font-style: italic;">#this allows traffic on the internal ip on port 8080</span>
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-d</span> 10.0.100.10<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">8080</span> <span style="color: #660033;">-j</span> ACCEPT</pre></div></div>

<p>nearly the same on the &#8220;weaker&#8221; server</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#this forwards traffic to the internal ip</span>
iptables <span style="color: #660033;">-A</span> PREROUTING <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-d</span> 74.125.39.99<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> DNAT <span style="color: #660033;">--to</span> 10.0.100.10:<span style="color: #000000;">8080</span>
<span style="color: #666666; font-style: italic;">#this allows traffic on the external interface on port 80</span>
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-d</span> 98.137.149.56<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT</pre></div></div>

<p>That&#8217;s it!</p>
<p>Perfectly save, perfectly scalable glassfish v3 (no apache bottleneck in your comet apps!)</p>
]]></content:encoded>
			<wfw:commentRss>http://dominikdorn.com/2010/04/tomcat-glassfish-jetty-port-80-iptables-nat/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

