ソースからインストールしたnginxをパッケージインストールへ切り替える方法
うちのWebサーバはnginxで運用していて、過去にspdy対応させるためにnginxをソースからインストールしていた。バージョンは1.7.2。
けど公式のパッケージの付加オプションを見てみたらv1.9.5(mainline)から既にhttp v2対応と書いて(※)あったので、試しにyumで入れてみた。
Packages for mainline version also have the following arguments:
--with-threads
--with-stream
--with-stream_ssl_module
and
--with-http_spdy_module
replaced with
--with-http_v2_module
インストール方法(mainlineの場合)
事前準備として公式にもあるようにyumのリポジトリへnginxを追加
To set up the yum repository for RHEL/CentOS, create the file named /etc/yum.repos.d/nginx.repo with the following contents:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1
Replace “OS” with “rhel” or “centos”, depending on the distribution used, and “OSRELEASE” with “5”, “6”, or “7”, for 5.x, 6.x, or 7.x versions, respectively.
うちはOSはCentOS 6.xなのでbaseurlは下記に書き換え。
http://nginx.org/packages/mainline/centos/6/$basearch/
1.念のため/etc/nginx以下をバックアップ
#tar zcvf nginx_conf_bak.tar.gz /etc/nginx/*
2.yumでインストール
#yum install nginx
nginx v1.7.2ではmake uninstallは準備されてないため、特に何もせずそのままyum installした。(うちの環境では結果的にはアンインストールは不要だった)
nginxを起動するとspdyじゃなくてhttp v2だよ!って怒られたけど、起動はした。
nginx: [warn] invalid parameter "spdy": ngx_http_spdy_module was superseded by ngx_http_v2_module in /etc/nginx/conf.d/server.conf:11
nginx: [warn] invalid directive "spdy_max_concurrent_streams": ngx_http_spdy_module was superseded by ngx_http_v2_module in /etc/nginx/conf.d/server.conf:28
(…以下同じようにspdy関連の設定でwarnが出る)
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
3.設定ファイル(うちではserver.conf)の書き換え
ssl時の動作をspdyからhttp2へ変更
listen 443 ssl http2;
spdy関連の設定がある場合、削除してhttp2のデフォルト値へ書き換え(必要ないかも?)
http2_chunk_size 8k;
http2_idle_timeout 3m;
http2_max_concurrent_streams 128;
http2_recv_timeout 30s;
以上で終わり。
確認にはChromeのデベロッパーツールを使って、Networkの表示列にProtocolを追加すると「spdy」から「h2」へ変更されている。
なんか色々アンインストールとかいるかと思ってたけど、普通にインストールしただけで終わったので楽ちんだった。nginxは色々とストレスフリーなところが好き。