We all know and dearly love Nginx. One very common way to use it is to put it in front of some other application server such as Tomcat, Node, or Tornado as a reverse proxy. About a year ago, Nginx got the ability to proxy WebSockets connections to a backend server that supports them.
The blogging software used to power this site, WordPress, has just had its 10th anniversary. In the last decade it has become incredibly popular, and currently accounts for about 18% of all websites. Due to my job at (mt) Media Temple, I’ve gotten to admin several popular blogs at various times over the years, and thus have a pretty good idea of how to optimize everything for good efficiency. In this WordPress configuration tutorial, I’m going to walk you through the production quality setup that I have for this blog, which makes use of Ubuntu Linux, Nginx, php5-fpm and MariaDB.
This blog doesn’t get a ton of traffic. At least not currently. But it’s pretty clear from the analytics that my post on proxying WebSockets with Nginx is by far the most popular thing I’ve written about to date. That article was fairly bare-bones, but people seem to find it useful, so I thought I’d just put the question out there: is there anything else related to the WebSockets functionality in Nginx you’d like to get some clarity on? Any examples you might find useful? If so, please just let me know in the comments, and I’ll do my best to make some new posts covering the areas of interest.
WebSockets are an exciting new technology designed to make it easier to create real time applications by providing a full-duplex communication channel between the browser and the server. In layman’s terms that means that information can be sent and received by the application at the same time. One of the easiest ways to write apps using WebSockets is to make use of the excellent Socket.io library, which is used in conjunction with Node. The usual strategy when building a Node app is to put Nginx in front of Node as a reverse proxy that serves any static content. This was a problem if you wanted to use WebSockets though, as Nginx didn’t know how to proxy those requests. Until now…
Speed is a Good Thing ™ when it comes to your site loading. Generally speaking, if people can’t start interacting with your site quickly, meaning within a few seconds of when they first get there, your engagement numbers are going to plummet. The folks over at Google are keenly aware of this and have therefore introduced a new protocol called SPDY which is designed to make the initial load time of modern web pages faster. It’s already in use at places such as GMail and Twitter, so this is not just a theoretical endeavor. My friends over at Automattic sponsored an initial implementation of SPDY for the Nginx web server, and I’ll explain how to use this cool new tech on your own sites.