我目前正在运行一个使用NGINX 1.11.9和openssl 1.0.2g的Ubuntu 16.04.1 LTS服务器。
根据我读过的一切,这些版本应该支持ALPN,但是当我在KeyCDN的HTTP / 2testing工具上运行testing时,我得到“ALPN不被支持”
而当我执行echo | openssl s_client -alpn h2 -connect example.com:443 | grep ALPN echo | openssl s_client -alpn h2 -connect example.com:443 | grep ALPN echo | openssl s_client -alpn h2 -connect example.com:443 | grep ALPN ,我得到:
depth=3 C = SE, O = AddTrust AB, OU = AddTrust External TTP Network, CN = AddTrust External CA Root verify return:1 depth=2 C = GB, ST = Greater Manchester, L = Salford, O = COMODO CA Limited, CN = COMODO RSA Certification Authority verify return:1 depth=1 C = GB, ST = Greater Manchester, L = Salford, O = COMODO CA Limited, CN = COMODO RSA Domain Validation Secure Server CA verify return:1 depth=0 OU = Domain Control Validated, OU = EssentialSSL Wildcard, CN = *.example.com verify return:1 No ALPN negotiated DONE
未启用ALPN将禁用HTTP2完全启用。 我如何启用ALPN?
编辑
nginx -V显示:
nginx version: nginx/1.11.9 built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3) built with OpenSSL 1.0.1f 6 Jan 2014 (running with OpenSSL 1.0.2g 1 Mar 2016) TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --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-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'
编辑#2
openssl version -a输出:
OpenSSL 1.0.2h 3 May 2016 built on: reproducible build, date unspecified platform: linux-x86_64 options: bn(64,64) rc4(16x,int) des(idx,cisc,16,int) idea(int) blowfish(idx) compiler: gcc -I. -I.. -I../include -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -Wa,--noexecstack -m64 -DL_ENDIAN -O3 -Wall -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM OPENSSLDIR: "/usr/local/ssl"
正如@AlexyTen所指出的那样,根本原因在于,尽pipe我安装了OpenSSL 1.0.2g,但是NGINX需要使用OpenSSL来构build,并且使用不支持ALPN的1.0.1f构build。
NGINX需要用OpenSSL 1.0.2或更高版本进行重build,然后重新安装。 我在网上find了一些教程,但因为我使用的是数字海洋服务器,所以我使用这个帮助主题来解决这个问题: https : //www.digitalocean.com/community/questions/how-to-get-already-安装-nginx的使用的-的OpenSSL 1-0-2换alpn
我首先需要安装一些新的库:
apt-get install libgeoip-dev libgd2-xpm-dev libperl-dev
然后我只是跑这个脚本: https : //gist.github.com/AJMaxwell/f6793605068813aae888216b02364d85
我现在重新启动使用sudo shutdown -r now并再次运行nginx -V 。 这次它给了我:
nginx version: nginx/1.11.0 built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) built with OpenSSL 1.0.2h 3 May 2016 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --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-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_perl_module=dynamic --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --with-openssl=/root/openssl-1.0.2h --add-module=/root/ngx_pagespeed-release-1.11.33.2-beta
我也运行keycdn的http2testing,它通过。
安装nginx ppa,它将支持ALPN:
sudo add-apt-repository ppa:nginx/stable sudo apt update sudo apt dist-upgrade -y
我已经创build了一个bash脚本,可以在Debian / Ubuntu,RHEL / CentOS和其他发行版中自动下载,编译和安装带有OpenSSL的Nginx。 由此产生的二进制文件与通过官方存储库分发Nginx的二进制文件完全相同,只是它带有最新版本的OpenSSL。
该脚本不会修改OpenSSL安装,只能修改Nginx二进制文件。 如果你不想依赖由非官方来源构build和发布的软件包,这是一个不错的select。