nginxにSPDYパッチあててみた

nginxにSPDYパッチあててみました。
参考サイトはこちら様。
http://techblog.heartrails.com/2013/01/using-spry-in-nginx.html
 

nginx自体はもうyumでインストールしていたので、configureオプションなどはほぼそのまま使用しています。 sbin-pathの変更と使わなそうなmail関係のモジュールを外すのとspdyモジュールを追加してビルドです!

環境

  • CentOS6.3 x86_64
  • nginx 1.3.14
  • openssl-1.0.1e

Install

念のため設定ファイルとかバックアップとっておきましょう。
現在のnginxのconfigureオプションを確認するにはnginx -Vです。

1
2
3
4
5
# nginx -V
nginx version: nginx/1.2.6
built by gcc 4.4.4 20100726 (Red Hat 4.4.4-13) (GCC) 
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx/ --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-cc-opt='-O2 -g'

これを元にビルドします。
まずはソースをダウンロードしてきてパッチあてます。

1
2
3
4
5
6
7
8
9
mkdir /usr/local/src/spdy
cd /usr/local/src/spdy
wget http://nginx.org/download/nginx-1.3.14.tar.gz
wget http://nginx.org/patches/spdy/patch.spdy-70_1.3.14.txt
wget http://www.openssl.org/source/openssl-1.0.1e.tar.gz
tar xvzf nginx-1.3.14.tar.gz
tar xvzf openssl-1.0.1e.tar.gz
cd nginx-1.3.14
patch -p1 < ../patch.spdy-69_1.3.14.txt

先ほどのconfigureオプションから--sbin-path=/usr/local/sbin/nginxへの変更、--with-mail,--with-mail_ssl_moduleの削除、--with-openssl=/usr/local/src/spdy/openssl-1.0.1e,--with-http_spdy_moduleを追加してインストールします。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
./configure --prefix=/etc/nginx/ --sbin-path=/usr/local/sbin/nginx --conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module \
--with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module \
--with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module \
--with-http_stub_status_module --with-file-aio --with-cc-opt='-O2 -g' \
--with-openssl=/usr/local/src/spdy/openssl-1.0.1e --with-http_spdy_module


Configuration summary
  + using system PCRE library
  + using OpenSSL library: /usr/local/src/spdy/openssl-1.0.1e
  + md5: using OpenSSL library
  + sha1: using OpenSSL library
  + using system zlib library

  nginx path prefix: "/etc/nginx/"
  nginx binary file: "/usr/local/sbin/nginx"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/var/run/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "/var/cache/nginx/client_temp"
  nginx http proxy temporary files: "/var/cache/nginx/proxy_temp"
  nginx http fastcgi temporary files: "/var/cache/nginx/fastcgi_temp"
  nginx http uwsgi temporary files: "/var/cache/nginx/uwsgi_temp"
  nginx http scgi temporary files: "/var/cache/nginx/scgi_temp"

make
sudo make install

確認

1
2
3
4
5
/usr/local/sbin/nginx -V
nginx version: nginx/1.3.14
built by gcc 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC) 
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx/ --sbin-path=/usr/local/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-file-aio --with-cc-opt='-O2 -g' --with-openssl=/usr/local/src/spdy/openssl-1.0.1e --with-http_spdy_module

いい感じです(´ω`)
作業してて気づいたんですけどnginxってSNIサポートしてるんですね! 今度検証してみたいです(脱線)

あとは起動スクリプト内のnginxへのパスを修正して実際にアクセスしてみます。

1
2
3
4
5
6
7
vim /etc/init.d/nginx
#nginx=${NGINX-/usr/sbin/nginx}
nginx=${NGINX-/usr/local/sbin/nginx}

vim /etc/sysconfig/nginx
#NGINX=/usr/sbin/nginx
NGINX=/usr/local/sbin/nginx
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
server {
  listen 443 ssl spdy default_server;
  server_name youyo.info;

  ssl_certificate       youyo.info.crt;
  ssl_certificate_key   youyo.info.key;

  location / {
    root /var/www/youyo.info;
    index index.html;
  }
}
1
2
3
4
/usr/local/sbin/nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
/etc/init.d/nginx restart

アクセスしてみると…?

spdy-test

chrome

無事SPDYで接続できたようです!
chromeのエクステンションやらchrome://net-internals/#spdyで確認できたので大丈夫なはずです!(不安

まとめ

  • 意外と簡単にできた
  • 接続が速くなったかはわかっていない(テストしてないから
  • SNIも試してみたくなった
  • 証明書の期限が切れる寸前だとわかった(あとあと一週間…

Comments