ある日 Nginx で HTTP/2 and SPDY indicator が青く輝いてくれなくなった件

ある日 Nginx で HTTP/2 and SPDY indicator が青く輝いてくれなくなった件

概要

Chrome Extention の HTTP/2 and SPDY indicator は
HTTP/2 で通信していることを確認する Chrome の拡張 Plugin です。

これがある日 not enable となっていたので
その対応をまとめます。

結果的に何が原因だったか

ALPN をサポートしていなかった為です。

ALPN Wiki

以下 HTTP/2 通信テストサービスでたどり着きました。

では何を対応するか

ALPN を サポートしている openssl を 1.0.2 系にし
Nginx を openssl 1.0.2 以上 で rebuild します。

2016/08/10 現時点の最新 1.0.2h

OpenSSL 1.0.2h インストール

1
2
3
4
5
6
7
8
# cd /usr/local/src
# wget https://www.openssl.org/source/openssl-1.0.2h.tar.gz
# tar xvf openssl-1.0.2h.tar.gz
# cd openssl-1.0.2h
# ./config
# make
# make test
# make install

現状の OpenSSL と置き換え

1
2
3
4
5
6
7
8
# which openssl
/usr/bin/openssl

# mv /usr/bin/openssl /root/
# ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl

# openssl version
OpenSSL 1.0.2h 3 May 2016

Nginx バージョン確認

1
2
# nginx -v
nginx version: nginx/1.11.3

現状の configure 状況確認

1
2
3
4
5
6
7
# nginx -V

nginx version: nginx/1.11.3
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
built with OpenSSL 1.0.2h 3 May 2016
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --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_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_perl_module=dynamic --add-dynamic-module=njs-1c50334fbea6/nginx --with-threads --with-stream --with-stream_ssl_module --with-stream_geoip_module=dynamic --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic'
  • Configure パラメータに --add-dynamic-module=njs-1c50334fbea6/nginx のような njs が含まれている場合は削除します。
    含まれている場合、 configure がこけます。 (前回記事参照)
  • 明示的に openssl を指定する為、以下パラメータを追加
1
--with-openssl=/usr/local/src/openssl-1.0.2h

現状の Nginx バージョンを変更しない前提で 1.11.3 の ソースをダウンロード

1
2
3
# cd /usr/local/src
# wget http://nginx.org/download/nginx-1.11.3.tar.gz
# tar xvf nginx-1.11.3.tar.gz

Nginx リビルド

1
2
3
4
5
6
# cd /usr/local/src/nginx-1.11.3
# ./configure --prefix=/etc/nginx --with-openssl=/usr/local/src/openssl-1.0.2h --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --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_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_perl_module=dynamic --with-threads --with-stream --with-stream_ssl_module --with-stream_geoip_module=dynamic --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic'

# make
# make test
# make install

version 確認

  • built with OpenSSL が 1.0.2h となっていることが確認できます。
1
2
3
4
5
6
# nginx -V
nginx version: nginx/1.11.3
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
built with OpenSSL 1.0.2h 3 May 2016
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --with-openssl=/usr/local/src/openssl-1.0.2h --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --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_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_perl_module=dynamic --with-threads --with-stream --with-stream_ssl_module --with-stream_geoip_module=dynamic --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic'

Nginx シンタックスチェック

1
2
3
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Nginx 再起動

1
# systemctl restart nginx

HTTP/2 and SPDY indicator 確認

青く輝きました!

HTTP/2 テストでも ALPN がサポートされていることが確認できました。

ある日 Nginx で HTTP/2 and SPDY indicator が青く輝いてくれなくなった件

https://kenzo0107.github.io/2016/08/09/2016-08-10-nginx-http2/

Author

Kenzo Tanaka

Posted on

2016-08-10

Licensed under

コメント