<?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>Cory O&#039;Daniel - These are just words &#187; nginx</title>
	<atom:link href="http://coryodaniel.com/index.php/tag/nginx/feed/" rel="self" type="application/rss+xml" />
	<link>http://coryodaniel.com</link>
	<description>Software development, thoughts, and randomness</description>
	<lastBuildDate>Thu, 17 Nov 2011 21:18:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Dealing with Adobe and Serving Socket Policy Servers via NGiNX and 10 lines of code</title>
		<link>http://coryodaniel.com/index.php/2009/06/10/dealing-with-adobe-and-serving-socket-policy-servers-via-nginx-and-10-lines-of-code/</link>
		<comments>http://coryodaniel.com/index.php/2009/06/10/dealing-with-adobe-and-serving-socket-policy-servers-via-nginx-and-10-lines-of-code/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 17:57:59 +0000</pubDate>
		<dc:creator>Cory O'Daniel</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[adobe flash]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[goddamnadobe]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[socket policy server]]></category>

		<guid isPermaLink="false">http://blog.vokle.com/?p=238</guid>
		<description><![CDATA[Ok, I don't even know where to start, but I guess I'll start by thanking Adobe for a such a high quality product (&#60;/sarcasm&#62;).  So we are working towards our new Vokle product, dubbed Vokle Everywhere (by me, just now).
So our new product allows for embeddability of chats and to do this we use ActionScript [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, I don't even know where to start, but I guess I'll start by thanking Adobe for a such a high quality product (&lt;/sarcasm&gt;).  So we are working towards our new Vokle product, dubbed Vokle Everywhere (by me, just now).</p>
<p>So our new product allows for embeddability of chats and to do this we use ActionScript 3.  I wouldn't say that AS3 has its short comings, except of course, Flex, but from time to time we have some issues with it.  Like not being able to override the 'Accept' header in a UrlRequest and other various dumb things.  Instead we moved to a mildly liberating open source <a href="http://code.google.com/p/as3httpclientlib/" target="_blank">AS3 HTTP Client.</a></p>
<p>AS3HTTPClientLib is pretty sweet, the only thing that sort of sucked was that we needed a Socket Policy Server, and the last thing I want to do is run another server (already have nginx, merb, wowza, yadayadayada) like this <a href="http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html" target="_blank">butthole suggests</a>.</p>
<p>Instead I figured, there has to be a way to just serve the crossdomain.xml file without being a giant hassle, especially since I am already serving it over HTTP for the same domain.  So I said, frig it, I'll do it with NGiNX since NGiNX is already serving my static files.  So the upside is when my servers are running, my 'policy server' is serving, the downside is, I had to finagle it so it wasn't a pain in the ass.  The problem is that ActionScript makes a 'weird' request when its looking for a policy server, and NGiNX doesn't understand it, so it servers a 400 Bad Request, well, it turns out that you can just do it hackety-hack and send your crossdomain.xml file as the 400 Error Page.  This works because AS isn't doing an HTTP Request, so it DOESNT CARE about the HTTP Status.  Bam, NGiNX Flash Socket Policy Server in 10 lines of code.</p>
<p>To enable 'socket policy server' functionality in NGiNX simply add another 'server' directive to your nginx.conf and drop your crossdomain.xml file in whatever folder your NGiNX server is serving its statics from.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">    server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
      listen <span style="color: #000000;">843</span>;
      server_name  localhost;
&nbsp;
      location <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        rewrite ^<span style="color: #7a0874; font-weight: bold;">&#40;</span>.<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>$ <span style="color: #000000; font-weight: bold;">/</span>crossdomain.xml;
      <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
      error_page <span style="color: #000000;">400</span> <span style="color: #000000; font-weight: bold;">/</span>crossdomain.xml;
&nbsp;
      location = <span style="color: #000000; font-weight: bold;">/</span>crossdomain.xml <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        root html;
      <span style="color: #7a0874; font-weight: bold;">&#125;</span>
    <span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p> </p>
<p>Sweet, start your nginx server and use the only useful thing from the Adobe blog post:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'printf &quot;&lt;policy-file-request/&gt;%c&quot;,0'</span> <span style="color: #000000; font-weight: bold;">|</span> nc 127.0.0.1 <span style="color: #000000;">843</span></pre></td></tr></table></div>

<p>And you should see your policy file.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Dealing+with+Adobe+and+Serving+Socket+Policy+Servers+via+NGiNX+and+10+lines+of+code+http://bit.ly/bumthC" title="Post to Twitter"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://digg.com/submit?url=http://coryodaniel.com/index.php/2009/06/10/dealing-with-adobe-and-serving-socket-policy-servers-via-nginx-and-10-lines-of-code/&amp;title=Dealing+with+Adobe+and+Serving+Socket+Policy+Servers+via+NGiNX+and+10+lines+of+code" title="Post to Digg"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-digg-big2.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://coryodaniel.com/index.php/2009/06/10/dealing-with-adobe-and-serving-socket-policy-servers-via-nginx-and-10-lines-of-code/&amp;t=Dealing+with+Adobe+and+Serving+Socket+Policy+Servers+via+NGiNX+and+10+lines+of+code" title="Post to Facebook"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-facebook-big2.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://coryodaniel.com/index.php/2009/06/10/dealing-with-adobe-and-serving-socket-policy-servers-via-nginx-and-10-lines-of-code/&amp;title=Dealing+with+Adobe+and+Serving+Socket+Policy+Servers+via+NGiNX+and+10+lines+of+code" title="Post to Reddit"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-reddit-big2.png" alt="Post to Reddit" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://coryodaniel.com/index.php/2009/06/10/dealing-with-adobe-and-serving-socket-policy-servers-via-nginx-and-10-lines-of-code/&amp;title=Dealing+with+Adobe+and+Serving+Socket+Policy+Servers+via+NGiNX+and+10+lines+of+code" title="Post to StumbleUpon"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-su-big2.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://coryodaniel.com/index.php/2009/06/10/dealing-with-adobe-and-serving-socket-policy-servers-via-nginx-and-10-lines-of-code/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MovingParts: Auto versioning your Javascript and CSS</title>
		<link>http://coryodaniel.com/index.php/2009/03/17/movingparts-auto-versioning-your-javascript-and-css/</link>
		<comments>http://coryodaniel.com/index.php/2009/03/17/movingparts-auto-versioning-your-javascript-and-css/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 21:37:55 +0000</pubDate>
		<dc:creator>Cory O'Daniel</dc:creator>
				<category><![CDATA[RubyDevelopment]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[autoversioning]]></category>
		<category><![CDATA[merb]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[rubyyui]]></category>

		<guid isPermaLink="false">http://blog.vokle.com/?p=219</guid>
		<description><![CDATA[This tutorial has a few moving parts.  It could be easily recreated with any stack, but for this post I used Nginx and Merb.
Why?
We like to keep things fast.  Two ways we do that is compress the hell out of our js/css and set the cache time on our assets to max.  This is cool [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial has a few moving parts.  It could be easily recreated with any stack, but for this post I used Nginx and Merb.</p>
<p><strong>Why?</strong></p>
<p>We like to keep things fast.  Two ways we do that is compress the hell out of our js/css and set the cache time on our assets to max.  This is cool to do and obvious, the thing that sucks is when its time to roll out new javascript or css making sure the clients get the updates.</p>
<p><strong>What?</strong></p>
<p>For this example I am using merb and merb-assets (<a href="http://github.com/wycats/merb/commit/9226ab290ff9ddf70aff0296b80960c5c47ecc93" target="_blank">w/ my latest merb patch</a>), nginx and <a href="http://github.com/coryodaniel/ruby-yui/tree" target="_blank">ruby-yui.</a></p>
<p><strong>Step1 - Add version info to assets with merb-assets</strong></p>
<p>In our code base we have a version for our site, set in a variable like WWW_VERSION.  Using this variable it is easy (with the newest merb-assets plugin) to modify the path of all of your assets on the fly.</p>
<p>Stick this in your init.rb...</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
WWW_VERSION = <span style="color:#996600;">&quot;0.1.0&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># this will make require_js &quot;application&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># =&gt; /javascripts/application.0.1.0.js</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># instead of /javascripts/application.js</span>
&nbsp;
<span style="color:#6666ff; font-weight:bold;">Merb::Plugins</span>.<span style="color:#9900CC;">config</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:asset_helpers</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:js_suffix</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;.#{WWW_VERSION}&quot;</span>
&nbsp;
<span style="color:#6666ff; font-weight:bold;">Merb::Plugins</span>.<span style="color:#9900CC;">config</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:asset_helpers</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:css_suffix</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;.#{WWW_VERSION}&quot;</span></pre></td></tr></table></div>

<p> </p>
<p>At this point in time merb is going to start outputting modified paths to your assets that contain version numbers.  This is cool because now when we modify javascript or css and bump the version number it will cause the clients that have cached the static assets to redownload them since the file path is different.  The part that sucks is renaming a bunch of javascript and css files.</p>
<p><strong>Step2 - Lying about file names</strong></p>
<p>Renaming a bunch of files does suck!  So don't do it.  Instead have that sneaky russian Nginx lie about it for you.</p>
<p>Stick this in you nginx.conf...</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">&nbsp;
location ~ ^<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>javascripts<span style="color: #000000; font-weight: bold;">|</span>stylesheets<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
&nbsp;
  rewrite ^<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>javascripts<span style="color: #000000; font-weight: bold;">|</span>stylesheets<span style="color: #7a0874; font-weight: bold;">&#41;</span>\<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>^\d<span style="color: #7a0874; font-weight: bold;">&#93;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>?:\.<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-<span style="color: #000000;">9</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">*</span>\.<span style="color: #7a0874; font-weight: bold;">&#40;</span>js<span style="color: #000000; font-weight: bold;">|</span>css<span style="color: #7a0874; font-weight: bold;">&#41;</span>$ <span style="color: #000000; font-weight: bold;">/</span>$<span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">/</span>$2.$<span style="color: #000000;">3</span>;
&nbsp;
  expires max;
&nbsp;
  <span style="color: #7a0874; font-weight: bold;">break</span>;
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p>This rewrite rule will make nginx route any javascript/stylesheet to the original file if it contains a version number.  So a request like to '/javascripts/application.0.1.0.js' will be rewritten to '/javascripts/application.js'.  Nifty.</p>
<p> </p>
<p><strong>Step3 - Compress those assets</strong></p>
<p>You can compress your assets in a number of ways, I'll go with shameless self promotion and recommend <a href="http://blog.vokle.com/index.php/2008/12/15/ruby-yui/" target="_blank">RubyYUI</a>.  RubyYUI is a ruby wrapper for the Java-based YUI  Compressor.  It lets you glob paths instead of doing one file at a time and add suffixes to files.  All sorts of things.</p>
<p>You can do something like this in a vlad or capistrano task during deployment.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'ruby-yui'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># this will cause the files to be compressed in place</span>
&nbsp;
Yui.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;./public/javascripts&quot;</span>,:stomp <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#ff3333; font-weight:bold;">:suffix</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">compress</span>
&nbsp;
Yui.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;./public/stylesheets&quot;</span>,:stomp <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#ff3333; font-weight:bold;">:suffix</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">nil</span>, <span style="color:#ff3333; font-weight:bold;">:type</span><span style="color:#006600; font-weight:bold;">=&gt;</span>:css<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">compress</span></pre></td></tr></table></div>

<p> </p>
<p>Now you have compressed assets in place in your deployed app and nginx will rewrite any versioned paths to your compressed files.  Bump your version number and all your clients will start getting the new compressed files.  Wee.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=MovingParts%3A+Auto+versioning+your+Javascript+and+CSS+http://bit.ly/9Wo2Q9" title="Post to Twitter"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://digg.com/submit?url=http://coryodaniel.com/index.php/2009/03/17/movingparts-auto-versioning-your-javascript-and-css/&amp;title=MovingParts%3A+Auto+versioning+your+Javascript+and+CSS" title="Post to Digg"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-digg-big2.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://coryodaniel.com/index.php/2009/03/17/movingparts-auto-versioning-your-javascript-and-css/&amp;t=MovingParts%3A+Auto+versioning+your+Javascript+and+CSS" title="Post to Facebook"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-facebook-big2.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://coryodaniel.com/index.php/2009/03/17/movingparts-auto-versioning-your-javascript-and-css/&amp;title=MovingParts%3A+Auto+versioning+your+Javascript+and+CSS" title="Post to Reddit"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-reddit-big2.png" alt="Post to Reddit" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://coryodaniel.com/index.php/2009/03/17/movingparts-auto-versioning-your-javascript-and-css/&amp;title=MovingParts%3A+Auto+versioning+your+Javascript+and+CSS" title="Post to StumbleUpon"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-su-big2.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://coryodaniel.com/index.php/2009/03/17/movingparts-auto-versioning-your-javascript-and-css/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

