運用中のNginxをノーメンテでバージョンアップ&HTTP2.0モジュールを導入

運用中のNginxをノーメンテでバージョンアップ&HTTP2.0モジュールを導入

概要

運用中の Nginx に HTTP2.0 モジュール http_v2_module を導入し
サイトのパフォーマンス向上を図ります。

※ Nginx 1.9.5 から http_spdy_modulehttp_v2_module に変更しています。

環境

  • CentOS Linux release 7.1.1503 (Core)
  • Nginx 1.9.3 インストール済み/稼働中

したいこと

  • Nginx のバージョンアップ (1.9.5 以上)
  • http_v2_module インストール

現状確認

1
2
3
4
5
6
7
# nginx -V

nginx version: nginx/1.9.3
built by gcc 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
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_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-threads --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_spdy_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'

※module や log, pid のパスは各環境に毎に異なります。

まずは 1.9.5 以上にバージョンアップして http_v2_module を導入したいと思います。

Nginx 1.9.6 インストール

今回は 2015.11.17 時点で最新の 1.9.6 をインストールします。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# cd /usr/local/src
# wget http://nginx.org/download/nginx-1.9.6.tar.gz
# tar xvf load/nginx-1.9.6.tar.gz
# cd nginx-1.9.6
# ./configure --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_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-threads --with-stream --with-stream_ssl_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 install

~~~ インストール完了 ~~~

# nginx -V
nginx version: nginx/1.9.6
built by gcc 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
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_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-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --with-http_geoip_module --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'

version が 1.9.6 となり
configure arguments に --with-http_v2_module が追加されていることがわかります。

要点は元々導入済み http_spdy_modulehttp_v2_module に変更しビルドです。
--with-http_spdy_module がなければ --with-http_v2_module 追加です。

nginx server ディレクティブ修正

ssl http2.0 対応する様、修正します

1
2
3
server {
- listen 443;
+ listen 443 ssl http2;

Nginx configure test & reload

  • configure test 実施します。
  • 以下のように syntax is ok が出ない場合は設定に誤りがあるので修正してください。
1
2
3
4
# nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
  • 設定を再読み込みします。
1
# nginx -s reload

上記で設定完了です。
これまでノーメンテでバージョンアップし、http_v2_module インストールができました。

早速 https スキーマとなるページにアクセスしてみましょう。

http2.0 設定確認

  • Chrome ブラウザの Extension SPDY インディケータで確認
  • FireFox 開発ツール> ネットワーク > ヘッダから確認

SPDY インディケータで確認

HTTP/2 and SPDY indicator

拡張モジュールをインストールして確認してみると
SPDY インディケータが青くなっていることが確認できます。

FireFox 開発ツール> ネットワーク > ヘッダから確認

参考サイト

運用中のNginxをノーメンテでバージョンアップ&HTTP2.0モジュールを導入

https://kenzo0107.github.io/2015/11/16/2015-11-17-versionup-nginx-without-maintenance/

Author

Kenzo Tanaka

Posted on

2015-11-17

Licensed under

コメント