<?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>Derek Neely &#187; Networking</title>
	<atom:link href="http://derekneely.com/category/networking/feed/" rel="self" type="application/rss+xml" />
	<link>http://derekneely.com</link>
	<description>...what I care to share...</description>
	<lastBuildDate>Thu, 06 Oct 2011 15:10:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Nginx (Mini How-to)</title>
		<link>http://derekneely.com/2009/10/nginx-mini-how-to/</link>
		<comments>http://derekneely.com/2009/10/nginx-mini-how-to/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 19:40:02 +0000</pubDate>
		<dc:creator>derek</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[Load balancer]]></category>
		<category><![CDATA[Nginx]]></category>

		<guid isPermaLink="false">http://derekneely.com/?p=440</guid>
		<description><![CDATA[Nginx (Engine-X) is a very light-weight powerful web proxy server and load balancer. This is a quick how-to on configuring a weighted load balancer using Nginx. I&#8217;ll skip past the installation on your system. Mine is currently running on an OpenBSD firewall using Packet Filter, and is how I will be covering the configuration. Nginx [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Nginx Home Page" href="http://wiki.nginx.org/Main" target="_blank"><img class="alignright size-full wp-image-311" title="Nginx" src="http://derekneely.com/wp-content/uploads/2009/06/nginx-logo.png" alt="Nginx" width="245" height="63" />Nginx</a> (Engine-X) is a very light-weight powerful web proxy server and load balancer. This is a quick how-to on configuring a weighted load balancer using Nginx. I&#8217;ll skip past the installation on your system. Mine is currently running on an OpenBSD firewall using Packet Filter, and is how I will be covering the configuration. Nginx is available and work on both Unix and Linux.</p>
<p>Configuring Nginx to start on system boot:</p>
<blockquote><p># vi /etc/rc.local</p>
<pre># start nginx
if [ -x /usr/local/sbin/nginx ]; then
   echo -n ' nginx'; /usr/local/sbin/nginx
fi</pre>
</blockquote>
<p>Load balance configuration (one public ip -&gt; 3 private servers):</p>
<blockquote><p># vi /etc/nginx/nginx.conf</p>
<pre>user  nobody;
worker_processes  2;
worker_rlimit_nofile 10240;

error_log  /var/log/nginx/error.log;

events {
   worker_connections  8192;
}

http {

   upstream  site {
        server 192.168.1.100:80 max_fails=2 fail_timeout=15 weight=3;
        server 192.168.1.101:80 max_fails=2 fail_timeout=15 weight=3;
        server 192.168.1.102:80 max_fails=2 fail_timeout=15 weight=1;
   }

   upstream  site_ssl {
        server 192.168.1.100:443 max_fails=2 fail_timeout=15 weight=3;
        server 192.168.1.101:443 max_fails=2 fail_timeout=15 weight=3;
        server 192.168.1.102:443 max_fails=2 fail_timeout=15 weight=1;
   }

   server {
        listen  AAA.BBB.CCC.DDD:80;

        location / {
             access_log off;
             proxy_connect_timeout 15;
             proxy_set_header Host $host;
             proxy_set_header X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_pass http://site;
        }
   }

   server {
        listen  AAA.BBB.CCC.DDD:443;

        ssl on;
        ssl_certificate /etc/ssl/ssl.cert/site.com.crt;
        ssl_certificate_key /etc/ssl/ssl.key/site.com.key;

        server_name site.com;

        location / {
             access_log off;
             proxy_connect_timeout 15;
             proxy_set_header Host $host;
             proxy_set_header X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header X_FORWARDED_PROTO https;
             proxy_pass http://site_ssl;
        }
   }
}</pre>
</blockquote>
<p>Should you have a chain file you need to add it to the end of the certificate file as such:</p>
<blockquote><p># cat /path/to/chain.file &gt;&gt; /etc/ssl/ssl.cert/site.com.crt</p></blockquote>
<p>Packet Filter Firewall Rules:</p>
<blockquote><p># vi /etc/pf.conf</p>
<pre>site_ext="AAA.BBB.CCC.DDD"
site_int1="192.168.1.100"
site_int2="192.168.1.101"
site_int3="192.168.1.102"

pass in quick log on $ext_if inet proto tcp from any to $site_ext port 80 keep state
pass in quick log on $ext_if inet proto tcp from any to $corp_ext port 443 keep state
pass out quick log on $int_if inet proto tcp from any to $site_int1 port 80 keep state
pass out quick log on $int_if inet proto tcp from any to $site_int1 port 443 keep state
pass out quick log on $int_if inet proto tcp from any to $site_int2 port 80 keep state
pass out quick log on $int_if inet proto tcp from any to $site_int2 port 443 keep state
pass out quick log on $int_if inet proto tcp from any to $site_int3 port 80 keep state
pass out quick log on $int_if inet proto tcp from any to $site_int3 port 443 keep state</pre>
</blockquote>
<p>Helpful Nginx server management commands:</p>
<p>Test Nginx Config file:</p>
<blockquote><p># nginx -t -c /etc/nginx/nginx.conf</p></blockquote>
<p>Restart Nginx server:</p>
<blockquote><p># kill -HUP `cat /var/run/nginx.pid`</p></blockquote>
<p>Stop Nginx server:</p>
<blockquote><p># kill -QUIT `cat /var/run/nginx.pid`</p></blockquote>
<p>If your like me and want to keep tabs on the load balancing (as in ipvsadm for Linux ldirectord) you can add a label to the end of each of your firewall rules:</p>
<blockquote><p>label &#8220;[some unique label for this rule]&#8221; (i.e. label &#8220;site-ext&#8221;)</p></blockquote>
<p>Then using pftop -v label you will see:</p>
<blockquote>
<pre>RULE LABEL           PKTS     BYTES     STATES MAX  ACTION   DIR
....
16   site-ext        867991   630495K   11833       Pass     In  ...
17   site-ext-ssl    29427    13315230  847         Pass     In  ...
18   site-int-1      13761450 6842062   813483      Pass     Out ...
19   site-int-1-ssl  234678   12345     12344       Pass     Out ...
....</pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://derekneely.com/2009/10/nginx-mini-how-to/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun With Active/Passive FTP and a PF Firewall</title>
		<link>http://derekneely.com/2009/09/fun-with-activepassive-ftp-and-a-pf-firewall/</link>
		<comments>http://derekneely.com/2009/09/fun-with-activepassive-ftp-and-a-pf-firewall/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 17:58:22 +0000</pubDate>
		<dc:creator>derek</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[Active FTP]]></category>
		<category><![CDATA[FTP]]></category>
		<category><![CDATA[OpenBSD]]></category>
		<category><![CDATA[Packet Filter]]></category>
		<category><![CDATA[Passive FTP]]></category>
		<category><![CDATA[PF]]></category>

		<guid isPermaLink="false">http://derekneely.com/?p=399</guid>
		<description><![CDATA[Here at work we&#8217;ve recently been moving off of a Linux/IPTables firewall setup to an OpenBSD/PF firewall. Well, anyone who has worked with firewalls knows the fun time you have with getting FTP to work through them. This includes client and server side. Well, this is my little &#8216;how-to&#8217; on doing just that with PF [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-281" title="OpenBSD" src="http://derekneely.com/wp-content/uploads/2009/06/openbsd.gif" alt="OpenBSD" width="168" height="140" />Here at work we&#8217;ve recently been moving off of a Linux/IPTables firewall setup to an OpenBSD/PF firewall. Well, anyone who has worked with firewalls knows the fun time you have with getting FTP to work through them. This includes client and server side. Well, this is my little &#8216;how-to&#8217; on doing just that with PF and PureFTP.</p>
<p>I originally started with <a title="PF: Issues with FTP" href="http://www.openbsd.org/faq/pf/ftp.html" target="_blank">this tutorial from OpenBSD</a> and was a good starting point but I felt it left out a few things.</p>
<p>First off. The tutorial above uses the ftp-proxy server on the box to allow proxying down to the ftp server. However, I didn&#8217;t exactly see any benefit of using it and didn&#8217;t seem to make anything easier. If I&#8217;m completely misunderstanding the usage of it please contact me and help me out. I DO want to do things right.</p>
<p>Here&#8217;s the overall layout of what is to happen:</p>
<blockquote><p>[Client] &lt;&#8212;&gt; [PF Firewall] &lt;&#8212;&gt; [FTP Server]</p></blockquote>
<p>Now, a few observations I&#8217;ve made while working with the firewall and maybe a bit clearer for others.</p>
<p>Here&#8217;s a great explanation of the overall FTP process from <a title="FTP Explained - Tech Republic" href="http://articles.techrepublic.com.com/5100-10878_11-5031026.html" target="_blank">Tech Republic</a>. Here&#8217;s the overall communication ports for the 2 different modes (as the PF firewall sees it &#8211; at least in my experience).</p>
<blockquote><p><strong>Active FTP:</strong><br />
-Inbound-<br />
&#8212; Authentication/Commands &#8212;<br />
Incoming:  21 (External interface &#8211; FW)<br />
Outgoing: 21 (Internal interface &#8211; FW)<br />
Incoming: 21 (FTP Server Interface)</p>
<p>-Outbound-<br />
&#8212; Data Transfer &#8212;<br />
Outgoing: &gt; 30000 (FTP Server Interface)<br />
Outgoing: &gt; 30000 (External interface &#8211; FW)</p>
<p><strong>Passive FTP:</strong><br />
-Inbound-<br />
&#8212; Authentication/Commands &#8212;<br />
Incoming:  21 (External interface &#8211; FW)<br />
Outgoing: 21 (Internal interface &#8211; FW)<br />
Incoming: 21 (FTP Server Interface)<br />
&#8212; Data Transfer &#8212;<br />
Incoming:  49000-51000 (External interface &#8211; FW)<br />
Outgoing: 49000-50000 (Internal interface &#8211; FW)<br />
Incoming: 49000-50000 (FTP Server Interface)</p>
<p>-Outbound-<br />
Outgoing: 49000-50000 (FTP Server Interface)<br />
Outgoing: 49000-50000 (External interface &#8211; FW)</p></blockquote>
<p>Alright enough chat and on to the code. First we need to configure the ftp server. In the  below examples I&#8217;ll cover PureFTP and ProFTPd for just the primary pieces of passive port configuration (I&#8217;ll give a nice ProFTP advanced configuration in a post to come). We&#8217;ll also assume the default &#8216;listening&#8217; port 21 of any standard FTP install/configuration. This is also on a Gentoo server so modify accordingly for your given distro.</p>
<p><strong>PureFTPd:</strong></p>
<blockquote><p>MISC_OTHER=&#8221;[various options/flags] -p 49000:51000 -P [Public IP]&#8220;</p></blockquote>
<p><strong>ProFTPd:</strong></p>
<blockquote><p>PassivePorts 49000 51000<br />
MasqueradeAddress [Public IP]</p></blockquote>
<p><strong>PF Firewall Rules:</strong> (Just the FTP Rules)</p>
<blockquote><p># Interface Definitions:<br />
ftp_ext=&#8221;[Public IP]&#8221;<br />
ftp_int=&#8221;[Private IP]&#8221;</p>
<p># NAT Rules<br />
nat on $ext_if from { $ftp_int } to any -&gt; $ftp_ext</p>
<p># Redirect Rules<br />
rdr pass on $ext_if inet proto tcp from any to $ftp_ext port 21 -&gt; $ftp_int port 21<br />
rdr pass on $ext_if inet proto tcp from any to $ftp_ext port 49000:51000 -&gt; $ftp_int</p>
<p># Firewall Rules<br />
pass out quick on $ext_if inet proto tcp from $ftp_ext to any port &gt; 1024 keep state</p>
<p>pass out quick log on $int_if inet proto tcp from any to $ftp_int port 21 keep state tag FTP label &#8220;ftp&#8221;<br />
pass out quick log on $int_if inet proto tcp from any to $ftp_int port 49000:51000 keep state tag FTP_PASV label &#8220;ftp-passive&#8221;</p></blockquote>
<p>That should be all you need for the PF rules and configuration on the FTP servers to get everything working and passing through. Feel free to contact me should you have any additional fixes or have a good explanation of how the ftp-proxy works and benefits of. I&#8217;ve just gotta find the time to do some experimenting.</p>
]]></content:encoded>
			<wfw:commentRss>http://derekneely.com/2009/09/fun-with-activepassive-ftp-and-a-pf-firewall/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx &#8211; failed (13: Permission denied) while reading upstream</title>
		<link>http://derekneely.com/2009/06/nginx-failed-13-permission-denied-while-reading-upstream/</link>
		<comments>http://derekneely.com/2009/06/nginx-failed-13-permission-denied-while-reading-upstream/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 11:03:12 +0000</pubDate>
		<dc:creator>derek</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[OpenBSD]]></category>
		<category><![CDATA[Permission denied]]></category>
		<category><![CDATA[Upstream fail]]></category>

		<guid isPermaLink="false">http://derekneely.com/?p=367</guid>
		<description><![CDATA[At my job we are moving to Nginx for the load balancing of our sites. Nginx is a very powerful load balancing/proxy server tool. It allows weighting, ssl acceleration, among other functionality while remaining light weight and easy to configure. In preperation for a large web services launch, I began to analyze some logs and [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-311" title="Nginx" src="http://derekneely.com/wp-content/uploads/2009/06/nginx-logo.png" alt="Nginx" width="210" height="54" />At my job we are moving to Nginx for the load balancing of our sites. Nginx is a very powerful load balancing/proxy server tool. It allows weighting, ssl acceleration, among other functionality while remaining light weight and easy to configure.</p>
<p>In preperation for a large web services launch, I began to analyze some logs and keep an eye on the system. I noticed one of the sites that we&#8217;ve already deployed was hammering our error messages in /var/log/nginx/error.log reading:</p>
<blockquote><p>2009/06/23 12:38:22 [crit] 808#0: *724154 open() &#8220;/var/nginx/tmp/proxy_temp/4/83/0000002834&#8243; failed (13: Permission denied) while reading upstream, client: XXX.XXX.XXX.XXX, server: xxx.host.com, request: &#8220;GET /dir/page.php&#8221;, upstream: &#8220;http://backendserverip/dir/page.php&#8221;, host: &#8220;host.com&#8221;, referrer: &#8220;http://referrer.com/apage.php&#8221;</p></blockquote>
<p>Upon reviewing the site I noticed some (not all) of the pages were only partially loading. The issue is exactly what the log says. Permission denied = Permission issue.</p>
<p>Check your /etc/nginx/nginx.conf (OpenBSD) file for the user nginx processes will run as:</p>
<blockquote><p>user  nobody;</p></blockquote>
<p>Or, do:</p>
<blockquote><p># ps aux | grep &#8220;nginx: worker process&#8221; | awk &#8216;{print $1}&#8217;<br />
nobody</p></blockquote>
<p>In both cases you see that I&#8217;m running the nginx worker process as user nobody. Now we need to check our permissions on: /var/nginx/tmp/proxy_temp</p>
<blockquote><p># ls -l /var/nginx/tmp/ | grep proxy_temp<br />
drwxrwx&#8212;  12 nobody  _nginx  512 Jun 23 13:10 proxy_temp</p></blockquote>
<p>Looks good. The directory is owned by nobody and is writeable by both nobody and the group _nginx. What could the issue be? Lets move up a level and check the permissions.</p>
<blockquote><p># ls -l /var/nginx | grep tmp<br />
drwx&#8212;&#8212;  5 _nginx  _nginx  512 May  7 11:54 tmp</p></blockquote>
<p>Ah ha! The parent directory is owned my _nginx:_nginx and is only writeable for that user. Our user &#8216;nobody&#8217; therefore does not have the permissions to write in here. So, we can do a few things. Either make the entire directory writeable by everyone or change the ownership.</p>
<blockquote><p># chmod 777 /var/nginx/tmp</p>
<p>or</p>
<p># chown nobody:_nginx /var/nginx/tmp</p></blockquote>
<p>This should cure your permissions issues and all pages should load completely (at least mine do!)</p>
]]></content:encoded>
			<wfw:commentRss>http://derekneely.com/2009/06/nginx-failed-13-permission-denied-while-reading-upstream/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

