ワイ、そして IT ときどき何か。

日々のとりとめのない記録

nginx 1.8 を 1.9 に変更して HTTP/2 に対応させる

himenaotaro.hatenablog.com ↑ 上が最新(2016年1月23日現在) の情報になります。

CentOS 6.5 などは nginx(エンジンエックス) が 1.8 なのでバージョンを stable の yum などでは上げることは出来ない。 なので、ソースコードからインストールをする必要がある。

以下を行うと yum によるアップデートなどが出来なくなるので自己責任で。

一. http://nginx.org/en/download.html から Mainline をダウンロード

二. ./configure, make, make install を行う

$ tar xvd nginx-1.9.9.tar.gz
$ cd nginx-1.9.9
$ ./configure (自分が好きな様に設定。e.g. --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx))
$ make
$ sudo make install

ちなみに、./configure に関して yum では以下のようになっている。

--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_spdy_module --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic

上述の --with-http_spdy_module は 1.9.5 以降では使えないので、 --with-http_v2_module オプションに変更する必要がある。

三. 環境変数を設定(以下は例)。

$ export PATH=/usr/local/nginx/sbin:$PATH

四. conf.d ディレクトリに入っているサーバの設定を以下のようにする

server {
  listen 443 ssl http2; # HTTP/2 を有効にする
  ...
}

もちろん HTTP/2 は TLS に対応させる必要があるのでキチンと SSL の設定などをすること。

五. $ nginx -V などできちんとなっているか確認して起動する。

今日買った以下の本がすごく役に立った。

http://www.amazon.co.jp/gp/product/4774178667/ref=as_li_ss_tl?ie=UTF8&camp=247&creative=7399&creativeASIN=4774178667&linkCode=as2&tag=2php-22www.amazon.co.jp