配置curl支持http2模块,并修改系统环境变量

背景说明:
系统默认curl一般不包含http2模块,需要自己编译添加
环境背景:
CentOS Linux release 7.6.1810 (Core)

一、查看环境依赖

1.查看系统环境

cat /etc/redhat-release

2.查看openssl版本

openssl version

注:如果没有,或者版本在1.0.1及以下则需要安装/更新
安装:yum install openssl openssl-devel -y
更新:yum update openssl openssl-devel -y

3.查看curl版本

curl -V

注:如果包含http2就是curl已经支持http2,否则需要配置,如:
在这里插入图片描述

二、安装依赖

1.安装编译工具

yum groupinstall "Development Tools"

2.编译安装nghttp2-devel

git clone https://github.com/tatsuhiro-t/nghttp2.git
cd nghttp2
autoreconf -i
./configure
make
make install
echo '/usr/local/lib' > /etc/ld.so.conf.d/custom-libs.conf
ldconfig
ldconfig -p| grep libnghttp2

注意:

  1. 只需要使用nghttp2时可以直接安装nghttp2,如yum install nghttp2 -y,需要编译curl时,则需要编译nghttp2
  2. 报系统访问不到https://github.com/时,可以尝试一下nslookup github.com,然后ping 解析出来的那个网站ip,就是测一下疏通一下。再git就能通了(其实看人品)

三、编译安装curl

1.下载curl最新版源码

https://curl.se/download.html

注:选一个最新的下载,我这里下的是8.5.0版本
在这里插入图片描述

2.导入服务器,然后安装

tar -zxf curl-8.5.0.tar.gz
cd curl-8.5.0
./configure --prefix=/usr/local/curl --with-nghttp2 --with-openssl
make && make install

注:

  1. –prefix是指定curl安装的位置
  2. –with-nghttp2编译curl时附加nghttp2模块
  3. –with-openssl编译curl时附加openssl模块,使用http2协议时,需要使用ssl加密。

3.校验是否成功

/usr/local/curl/bin/curl -V

注:如果包含http2模块时,则证明安装成功,如:
在这里插入图片描述

4.配置成系统默认curl

export PATH="/usr/local/curl/bin:$PATH"
source ~/.bashrc
ln -sf /usr/local/curl/bin/curl /usr/bin/curl

注:

  1. export PATH 配置环境变量
  2. source ~/.bashrc 刷新环境变量配置
  3. ln -sf 将系统默认的curl符号链接指向新编译的curl二进制文件

四、使用curl校验http2

curl --http2 -I https://www.example.cn -k

注:

  1. –http2访问http2协议的网站,必须加上,不然会默认使用http1访问
  2. -k 取消ssl证书校验,当网站使用自签证书时适用

五、附加一个nginx的http2.0配置

1.nginx模块

在这里插入图片描述
注:必须要带有with-http_ssl_module和with-http_v2_module

2.nginx.conf配置

在这里插入图片描述

六、附加一个chrome查看网站http2协议

1.打卡调式模式的控制台

f12–>Console

2.输入命令查看

window.chrome.loadTimes ()

注:

  1. 查看npnNegotiatedProtocol
  2. 显示h2时表明是http2
    在这里插入图片描述
  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值