<?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>ReadyState4 &#187; Apache</title>
	<atom:link href="http://readystate4.com/category/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://readystate4.com</link>
	<description>JavaScript, Web Development, Ruby, and Technology.</description>
	<lastBuildDate>Fri, 27 Jan 2012 18:37:32 +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, Apache, and Node all living harmony.</title>
		<link>http://readystate4.com/2011/07/15/nginx-apache-and-node-all-living-harmony/</link>
		<comments>http://readystate4.com/2011/07/15/nginx-apache-and-node-all-living-harmony/#comments</comments>
		<pubDate>Fri, 15 Jul 2011 22:28:00 +0000</pubDate>
		<dc:creator>Mauvis</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[node]]></category>

		<guid isPermaLink="false">http://readystate4.com/?p=367</guid>
		<description><![CDATA[So here&#8217;s two problems you want to solve: You want to optimize static content You have an Apache install that&#8217;s hosting a bunch of sites and friend&#8217;s sites through vhosts. One of your blogs is getting a lot of hits and you want to optimize it&#8217;s static content &#8211; or even the static content of [...]]]></description>
			<content:encoded><![CDATA[<p>So here&#8217;s two problems you want to solve:</p>
<h3>You want to optimize static content</h3>
<p>You have an Apache install that&#8217;s hosting a bunch of sites and friend&#8217;s sites through vhosts. One of your blogs is getting a lot of hits and you want to optimize it&#8217;s static content &#8211; or even the static content of all sites. You&#8217;re not quite ready for a CDN-type deal, just to place the content outside of Apache and into something more lighter-weight so it&#8217;s not running through WordPress / Apache and unnecessarily using up threads (at roughly 2mb a thread).</p>
<h3>You want all your web apps on port 80!</h3>
<p>You started really getting into Node (or Ruby on Rails or Django) but every web app needs to be binded to it&#8217;s own port and port 80 is taken by your Apache which is hosting a lot. You don&#8217;t want to be giving out the url: http://mycoolnewapp.com:81.</p>
<p>Sure you can use Apache&#8217;s <a href="http://httpd.apache.org/docs/1.3/mod/mod_proxy.html">proxypass</a> but you&#8217;re gaining overhead and, in case of Node (or Ruby&#8217;s <a href="http://rubyeventmachine.com/">EventMachine</a> or Python&#8217;s <a href="http://twistedmatrix.com/trac/">Twisted</a>), you&#8217;re losing the whole point of having an optimized, non-blocking / non-threaded, web app.</p>
<h3>The solution</h3>
<p><a href="http://wiki.nginx.org/">Nginx</a>! Nginx is a web server, <a href="http://en.wikipedia.org/wiki/Reverse_proxy">reverse-proxy</a>, load balancer, and mail server all in one. Like Node, it was built with the concept of the event loop, not threads so it&#8217;s highly optimized for high concurrency. The idea is to setup Nginx to be a reverse-proxy for all your other services.</p>
<p>I&#8217;ll skip over how to install Nginx as it&#8217;s pretty straightforward and you can google it. I&#8217;ll go over the main steps to getting Apache to work through Nginx &#8211; it&#8217;s truly easy, I did it on my first try. The only problem that I encountered is that since the user only interfaces with Nginx &#8211; it&#8217;s Nginx that is making the requests to Apache / Node. So from Apache&#8217;s perspective, all requests are coming from 127.0.0.1. We also fix this in the steps below.</p>
<ol>
<li>Once Nginx is installed, edit your /etc/httpd/conf/httpd.conf so that it listens on another port. Say 127.0.0.1:8080.</li>
<li>Switch all your vhosts to also listen on this port.</li>
<li>Edit your /etc/nginx/nginx.conf file. Make sure it&#8217;s set to listen on port 80 and add a server entry per each apache vhost. Here&#8217;s an example:
<pre>
    server {
           listen       80;
           server_name  mysite.com;

	   location / {
                    proxy_pass http://127.0.0.1:8080;
                    include /etc/nginx/conf.d/proxy.conf;
           }
    }
</pre>
</li>
<li>Next we&#8217;ll add that proxy.conf reference by creating /etc/nginx/conf.d/proxy.conf:
<pre>
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 8m;
client_body_buffer_size 256k;
proxy_connect_timeout 60;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_buffer_size 4k;
proxy_buffers 32 256k;
proxy_busy_buffers_size 512k;
proxy_temp_file_write_size 256k;
</pre>
</li>
<li>At his point you need to install <a href="http://stderr.net/apache/rpaf/">mod-rpaf</a> for Apache. This enable Apache to use the extra headers Nginx is passing in the request. If you&#8217;re using a flavor of Linux that uses apt-get you&#8217;re in luck. Just run: sudo apt-get install libapache2-mod-rpaf. If you&#8217;re using a system that uses Yum, you&#8217;ll have to compile it yourself. Just follow the steps <a href="http://binarysushi.com/blog/2009/aug/19/CentOS-5-3-python-2-5-virtualevn-mod-wsgi-and-mod-rpaf/">here</a>.
</li>
</ol>
<p>As for serving static content. Inside each &#8220;server&#8221; declaration you can add the following (modified to your taste):</p>
<pre style="overflow: auto;">
       location ~* ^.+\.(jpg|jpeg|gif|png|ico|tgz|gz|pdf|rar|bz2|exe|ppt|txt|tar|mid|midi|wav|bmp|rtf) {
            root /folder/to/static/files;
            expires 90d;
       }
       location ~* ^.+\.(css|js)$ {
            root /folder/to/static/files;
            expires 30d;
      }
</pre>
<p><br ><br />
Ad that&#8217;s it you&#8217;re done!</p>
<h3>Additional reading</h3>
<p><a href="http://blog.martinfjordvald.com/2010/07/nginx-primer/">Nginx Primer</a><br />
<a href="http://blog.martinfjordvald.com/2011/02/nginx-primer-2-from-apache-to-nginx/">Nginx Primer 2: From Apache to Nginx</a><br />
<a href="http://kbeezie.com/view/apache-with-nginx/">Apache with Nginx</a><br />
<a href="http://kbeezie.com/view/nginx/">Really solid config samples</a></p>
]]></content:encoded>
			<wfw:commentRss>http://readystate4.com/2011/07/15/nginx-apache-and-node-all-living-harmony/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Expires header doesn&#8217;t work on the iPhone / iPad</title>
		<link>http://readystate4.com/2010/12/17/expires-header-doesnt-work-on-the-iphone-ipad/</link>
		<comments>http://readystate4.com/2010/12/17/expires-header-doesnt-work-on-the-iphone-ipad/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 20:49:07 +0000</pubDate>
		<dc:creator>Mauvis</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://readystate4.com/?p=109</guid>
		<description><![CDATA[I&#8217;m optimizing the web views of an iPhone app in preparation for Christmas traffic and one of the ideas I had was to use small increments of Expires header to cache files client-side. I assumed this would be no problem as all my work with Safari on the iPhone has shown it a very capable [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m optimizing the web views of an iPhone app in preparation for Christmas traffic and one of the ideas I had was to use small increments of <a href="http://developer.yahoo.com/performance/rules.html">Expires header</a> to cache files client-side. I assumed this would be no problem as all my work with Safari on the iPhone has shown it a very capable browser—as good as any desktop one.</p>
<p>Turns out after some testing that using Expires Header isn&#8217;t possible— not because of cache size limitations as one would assume. It looks like the guys in Cupertino wanted to limit this ability on the iOS as every HTTP request made by an iOS device issues a <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">pragma: no-cache</a> directive. I&#8217;ve yet to understand why. Better fire up more memcache servers.</p>
<p>Here&#8217;s the raw headers if interested:</p>
<pre style="overflow:hidden;">GET /expires/ HTTP/1.1
Host: readystate4.com
User-Agent: Mozilla/5.0 (iPad; U; CPU OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Cookie: __utma=244034822.428964265.1285289496.1290546798.1290723961.13; __utmz=244034822.1285289496.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=1.1229958817.1285277083.1288920090.1292540519.14; __utmc=1; __utmz=1.1285277083.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
Pragma: no-cache
Connection: keep-alive</pre>
]]></content:encoded>
			<wfw:commentRss>http://readystate4.com/2010/12/17/expires-header-doesnt-work-on-the-iphone-ipad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Always remember: you can&#8217;t &#8220;expires header&#8221; an HTTP POST</title>
		<link>http://readystate4.com/2010/12/17/always-remember-you-cant-expires-header-an-http-post/</link>
		<comments>http://readystate4.com/2010/12/17/always-remember-you-cant-expires-header-an-http-post/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 17:34:37 +0000</pubDate>
		<dc:creator>Mauvis</dc:creator>
				<category><![CDATA[Apache]]></category>

		<guid isPermaLink="false">http://readystate4.com/?p=103</guid>
		<description><![CDATA[This includes ajax content (which to the server is just a standard HTTP request.) This makes sense since POST should only be used for storing or updating data. Thanks to this page.]]></description>
			<content:encoded><![CDATA[<p>This includes ajax content (which to the server is just a standard HTTP request.) This makes sense since POST should only be used for storing or updating data. </p>
<p>Thanks to this <a href="http://blog.httpwatch.com/2009/08/07/ajax-caching-two-important-facts/">page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://readystate4.com/2010/12/17/always-remember-you-cant-expires-header-an-http-post/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to add Ruby (.rhtml) support to your existing MAMP setup with eRuby</title>
		<link>http://readystate4.com/2008/08/18/how-to-add-ruby-rhtml-support-to-your-existing-mamp-setup-with-eruby/</link>
		<comments>http://readystate4.com/2008/08/18/how-to-add-ruby-rhtml-support-to-your-existing-mamp-setup-with-eruby/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 02:30:50 +0000</pubDate>
		<dc:creator>Mauvis</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://readystate4.com/2008/08/18/how-to-add-ruby-rhtml-support-to-your-existing-mamp-setup-with-eruby/</guid>
		<description><![CDATA[Adding Ruby HTML support to your existing MAMP setup is great for experimenting and for building quick single serving apps where a whole Rails setup would be overkill. This is how I added Ruby RHTML page support to my current MAMP setup: Download and compile eRuby Download and unzip http://www.modruby.net/en/index.rbx/eruby/download.html Go to the unzipped directory [...]]]></description>
			<content:encoded><![CDATA[<p>Adding Ruby HTML support to your existing <a href="http://www.mamp.info/en/index.php">MAMP</a> setup is great for experimenting and for building quick single serving apps where a whole Rails setup would be overkill. This is how I added Ruby RHTML page support to my current MAMP setup:</p>
<h3>Download and compile eRuby</h3>
<ol>
<li>Download and unzip <a href="http://www.modruby.net/en/index.rbx/eruby/download.html">http://www.modruby.net/en/index.rbx/eruby/download.html</a></li>
<li>Go to the unzipped directory in terminal</li>
<li>type ./configure.rb</li>
<li>type make</li>
<li>type make install</li>
<li>Copy the generated eruby file to your local cgi-bin</li>
</ol>
<h3>Modify your httpd.conf settings</h3>
<ol>
<li>add this line to add the rhtml support:
<pre>AddType application/x-httpd-eruby .rhtml
Action application/x-httpd-eruby /cgi-bin/eruby</pre>
</li>
<li>And modify this line so your server will look for index.rhtml pages in directories:<br />
<code>DirectoryIndex index.html index.shtml index.rhtml</code></li>
</ol>
<h3>Running straight .rb files outside your cgi-bin folder (optional)</h3>
<p>You can run any scripts from your cgi-bin if you properly add the #!(she bang) location to your ruby intepreter at the top of your scripts, but you can also make these scrips run outside of your cgi-bin by just adding this line to your httpd.config, just add the .rb extension to the filename:</p>
<pre>AddHandler cgi-script .rb</pre>
<p>I was doing this for awhile so I could execute scripts through the web but the RHTML method is better. Still, there could be applicable reasons for a person to want to do this.  Just keep in mind, that when accessing Ruby scripts directly from a webpage you must at least specify a content-type (puts: &#8220;content-type: text/plain\n&#8221;) in your header or use the convenient <a href="http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html">cgi class</a> from the Ruby standard library that does that (and a whole lot more) for you.</p>
<h3>Improving Performance (optional)</h3>
<p>The above is a really quick way to add Ruby support to your local webserver however, there&#8217;s one downside &#8211; it has to start up the Ruby interpreter everytime you hit an rhtml file with your browser. If you want something a little more dedicated look into the <a href="http://modruby.net/en/">mod_ruby</a> apache module which embeds a Ruby interpreter into Apache&#8217;s (inside your web server&#8217;s memory), to let Ruby CGI scripts execute natively, so scripts start up and run far faster. This is the equivalent as mod_php for PHP, that&#8217;s built into your MAMP setup.</p>
<p>Additionally, as a speed boost, you could use <a href="http://www.fastcgi.com/">fast cgi</a> to keep the eRuby interpreter instantiated, if for some reason you can&#8217;t use mod_ruby.</p>
<p><strong>Helpful links:</strong></p>
<p>http://www.rubycentral.com/book/web.html</p>
]]></content:encoded>
			<wfw:commentRss>http://readystate4.com/2008/08/18/how-to-add-ruby-rhtml-support-to-your-existing-mamp-setup-with-eruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

