美文网首页
Nginx 启用 HTTP/2 不生效的原因排查

Nginx 启用 HTTP/2 不生效的原因排查

作者: awker | 来源:发表于2020-03-20 00:25 被阅读0次

nginx 相关信息如下

# /usr/local/openresty/nginx/sbin/nginx -V
nginx version: openresty/1.13.6.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.0 --add-module=../iconv-nginx-module-0.14 --add-module=../echo-nginx-module-0.61 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.13 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.15 --add-module=../rds-csv-nginx-module-0.09 --add-module=../ngx_stream_lua-0.0.5 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-pcre --with-http_realip_module --with-http_sub_module --with-http_stub_status_module --with-stream --with-stream_ssl_module --add-module=/usr/local/src/nginx-module-vts-0.1.18 --with-http_v2_module --with-stream --with-stream_ssl_module --with-http_ssl_module

可以看到 nginx 版本为 openresty/1.13.6.2、openssl 版本为OpenSSL 1.0.2k-fips 、nginx 编译参数也启用了HTTP/2 --with-http_v2_module

在 nginx 站点配置也启用了 http2

server {
    listen 443 http2;
    server_name www.foobar.cn;
    略……
}

但访问站点时,看到的协议还是 http/1.1


排查过程:
折腾了好久好久,排除了 nginx 版本、openssl 版本、站点是否启用 http2 、linux 系统环境

突然记起来,站点前面通过 CNAME 配置了 WAF,于是验证了一下

1、临时在本地 hosts 绑定 IP 和域名,访问时看到 http/2 生效了


2、不在本地 hosts 绑定 IP 和域名,直接访问时看到 http/2 没有生效


问题原因找到,nginx 是已经启用了 http/2 的,并且已经生效

之所以直接访问时,看到的协议还是 http/1.1,是因为站点前面的 WAF 不支持 http/2

相关文章

网友评论

      本文标题:Nginx 启用 HTTP/2 不生效的原因排查

      本文链接:https://www.haomeiwen.com/subject/okqdyhtx.html