51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

Nginx启用http2不生效

Nginx启用http2不生效,可以检查openssl版本是不是过低

查看当前openssl版本
openssl version

|---|-----------------| | 1 | openssl version |

OpenSSL 1.0.1e-fips 11 Feb 2013

查看完版本可知,当前版本是1.0.1的,版本过老,需要升级到1.0.2才可以支持http2协议

注意:只需要在编译nginx的时候指定1.0.2版本的openssl就可以了

平滑编译方法:

1、下载openssl1.0.2源码包
cd /usr/local/src/ wget https://www.openssl.org/source/openssl-1.0.2o.tar.gz tar zxf openssl-1.0.2o.tar.gz

|-------|------------------------------------------------------------------------------------------------------------| | 1 2 3 | cd /usr/local/src/ wget https://www.openssl.org/source/openssl-1.0.2o.tar.gz tar zxf openssl-1.0.2o.tar.gz |

2、查看当前nginx编译安装时安装了哪些模块
nginx -V

|---|----------| | 1 | nginx -V |


nginx version: nginx/1.12.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) built with OpenSSL 1.0.2k-fips TLS SNI support enabled configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module

|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 | nginx version: nginx/1.12.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) built with OpenSSL 1.0.2k-fips TLS SNI support enabled configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module |

3、增加--with-openssl=/usr/local/src/openssl-1.0.2o重新编译**(注意:最后不需要执行make install)**
cd /usr/local/src/ wget http://nginx.org/download/nginx-1.12.2.tar.gz tar zxf nginx-1.12.2.tar.gz cd /usr/local/src/nginx-1.12.2 ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-http_realip_module --with-openssl=/usr/local/src/openssl-1.0.2o make

|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 | cd /usr/local/src/ wget http://nginx.org/download/nginx-1.12.2.tar.gz tar zxf nginx-1.12.2.tar.gz cd /usr/local/src/nginx-1.12.2 ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-http_realip_module --with-openssl=/usr/local/src/openssl-1.0.2o make |

4、备份源文件并替换nginx的二进制文件
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak cp objs/nginx /usr/local/nginx/sbin/nginx

|-----|----------------------------------------------------------------------------------------------------------| | 1 2 | mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak cp objs/nginx /usr/local/nginx/sbin/nginx |

5、验证
nginx -V

|---|----------| | 1 | nginx -V |


nginx version: nginx/1.12.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) built with OpenSSL 1.0.2k-fips TLS SNI support enabled configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-http_realip_module --with-openssl=/usr/local/src/openssl-1.0.2o

|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 | nginx version: nginx/1.12.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) built with OpenSSL 1.0.2k-fips TLS SNI support enabled configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-http_realip_module --with-openssl=/usr/local/src/openssl-1.0.2o |

此时访问网站,可以看到http2启用成功

查看网站是否启用http2协议方法:https://blog.whsir.com/post-2975.html

赞(0)
未经允许不得转载:工具盒子 » Nginx启用http2不生效