「nginxでアクセスログにspdyのバージョンを出す」の時と同様にlog_formatで出力できる。
nginx 1.9.3 + patch.http2-v2で試す
環境構築は「nginx1.9.3 HTTP/2 パッチを試す」
設定
http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' 'h2:$http2'; access_log /var/log/nginx/access.log main; server { listen 443 ssl http2 ; ssl_prefer_server_ciphers on; ...
このように、log_formatの部分に$http2を加えるだけ。
出力
以上の設定を行い、nginxを再起動すると
http2で通信しているときは、$http2がh2になります
192.168.0.21 - - [18/Aug/2015:20:25:11 +0900] "GET / HTTP/1.1" 200 144 "-" h2:h2
非対応ブラウザの場合、h2の所は何も表示されません
192.168.0.21 - - [18/Aug/2015:20:25:40 +0900] "GET / HTTP/1.1" 304 0 "-" h2:
正確にはネゴシエーション時の識別子が表示される。
- $http2 negotiated protocol identifier if the request came via HTTP/2 ("h2", "h2c"), or empty value.