SPDY with nginx on CentOS 6

spdy icon

Enable SPDY with nginx

Hi, get used to it, I am a lazy server administrator. Hence, a late post.

If you are hosting your blog/website/”whatever”  on a CentOS server, AND you want to get ‘SPDY’ module enabled for your server, and is afraid to compile a package (nginx) on CentOS,  then read on.

‘SPDY’ is a new toy (not so new) server admins love to try and it’s worth it, why simply because google, facebbok, twitter  etc. uses it. It was enough to get me curious. It is pretty simple actually, if you are using ‘nginx’ from default installation, then it is obvious you have ‘nginx 1.0.15’ as of now which does not support ‘SPDY’ yet.

Let’s get to business and get ‘SPDY; module for ‘nginx.’ Steps follows as below:

1. Download nginx ‘src’ package from:

http://nginx.org/packages/centos/6/SRPMS/

2. You would also need some of the pre-requsite packages to compile an RPM, so install the following:


# yum install rpm-build gcc make

3. Let’s install that nginx source package, installing the src RPM does not actually install the package, instead it will create a directory under your user home directory called ‘rpmbuild’ in which you will find the source code and a ‘.spec’ file. That .spec file is the one most important while building RPM packages.


# rpm -ivh <a href="http://nginx.org/packages/centos/6/SRPMS/nginx-1.6.0-1.el6.ngx.src.rpm">nginx-1.6.0-1.el6.ngx.src.rpm</a>

NOTE: it’s always a good idea to get the latest package, why, well because it’s latest and have atleast some improvements from the previous one :), but do check the dependencies. As such ‘nginx’ does not have any dependencies, so you are good to go.

4. Go to ‘~/rpmbuild/SPEC’ directory and run the following command (it is always a good idea to ‘vi’ that .spec file and make sure “%{?with_spdy:–with-http_spdy_module} ” is in there, it will be there by default but it never hurts to cross check).


$ rpmbuild -ba nginx.spec

NOTE: Do not make RPMS as root, not a good idea.

5. Once that command finishes it’s operation (it will ‘configure’, ‘make’ and ‘compile RPM’ package for you lazy people out there, ready for installation 😛 ). You may go ahead and install it using yum as:


# yum localinstall nginx

check if SPDY is enabled with your nginx installation:

To check, simply run ‘nginx -V‘ and look for “–with-http_spdy_module“. If you have that, it means that your nginx is configured with SPDY and you can continue further.

make changes in nginx conf files:

To actually enable SPDY, you would need to add it in your configuration file (default.conf or virtual.conf, wherever you have your server block configured) and add the following:

server {
listen       443 ssl spdy;
 add_header   Alternate-Protocol  443:npn-spdy/2;
 server_name  _server_name_;

Things to keep in mind before upgrading:

1. Installation of nginx from RPM will rename all your configuration files as: ‘file.conf.rpmsave‘, REMEMBER to rename them back to actual names or you will be pulling your hair out figuring out what went wrong here.

2. BACKUP!, everything. (I even backed up my document root along with the database). This way you don’t have to pray much as you will have a chance and a backup to revert back the changes.

3. ‘SPDY’ works only with SSL certs enabled. Hence, if your blog or website is not running over SSL, you cannot expect to see any difference as the requests to the web server will be in plain text and ‘SPDY’ is not for you.

How to check if spdy is enabled for your website:

Easy, install a google chrome extension called ‘SPDY indicator‘ in the chrome store and it will tell you if your website is using ‘SPDY’ or not.

Alternatively, visit “spdycheck” and fill in your domain name, it will let you know if you are using SPDY or not.

I hope this had been informative for you. Check back for further tutorials. Adios for now!

Leave a Reply

Your email address will not be published. Required fields are marked *