Adding Support to SPDY Protocol on Nginx with Zero Downtime

As fast as the SPDY protocol is the post today..

Looking for articles about how to add SPDY support to Nginx, I just found ones showing the installation process from scratch. But, what if I already have a running server?

To accept SPDY, Nginx needs to be compiled with the flag --with-http_spdy_module. But remember, our goal is to pull it off with zero downtime.

Suppose we have a Rails application running on Nginx and we wanna add support to SPDY protocol.

Passenger is our application server, thus, the web server needs to be compiled with it. How to proceed?

First, ensure you have passenger gem installed:

gem install passenger

Now, we need to reinstall Nginx with the quoted flag above. Running rvmsudo passenger-install-nginx-module we can start the installation process. But how we are going to customize the installation process, let's download and extract first Nginx's source code.

wget http://nginx.org/download/nginx-1.6.2.tar.gz
tar -xvf nginx-1.6.2.tar.gz
pwd

Ok, the last issued command was pwd cause we need to know the path. Now, we need to compile Nginx together with Passenger:

rvmsudo passenger-install-nginx-module

It will ask for the languages we are interested in, and later, it will ask if we wanna automatically download and install Nginx or customize the installation, we choose the second option.

It will ask for the path where Nginx's source code is, we tell, later, it will ask where we want to install Nginx, I keep the default and go ahead.

On latest and most important step, we need to specify extra arguments we want to pass, we add --with-http_spdy_module, go forward and voilá, after a while it will finish.

To ensure our new binary has the flag, we access its path (/opt/nginx/sbin) and run ./nginx -V to see all included modules.

Now, we just need to add the spdy keyword in our config files, like below:

listen 443 ssl spdy;

Once done, we run sudo pkill nginx && sudo service nginx start to restart Nginx.

Finally, we can enter this website http://spdycheck.org and confirm the progress.

See you.

Written on November 24, 2014

Share: