curl 不支持http2
安装php时开启的curl扩展没有支持http/2,在发送调用一些必须以http/2才能请求的接口会出现异常情况。建议在默认开启curl 的 http/2本帖最后由 gaoxu529 于 2024-10-25 23:51 编辑
目前通过以下步骤已解决。
1. 获取punum ,后面要用到
cat /proc/cpuinfo |grep "processor"|wc -l
2. 下载nghttp2 源码
wget -O nghttp2-1.42.0.tar.gz https://github.com/nghttp2/nghttp2/archive/refs/tags/v1.42.0.tar.gz
3. 编译nghttp2
tar -zxf nghttp2-1.42.0.tar.gz
cd nghttp2-1.42.0
rm -rf /usr/local/nghttp2
autoreconf -i
automake
autoconf
./configure --prefix=/usr/local/nghttp2
make clean
make -j ${cupnum}
make install
4、下载curl源码
wget https://download.bt.cn/src/curl-7.70.0.tar.gz
5、编译curl
tar -zxf curl-7.70.0.tar.gz
cd curl-7.70.0
rm -rf /usr/local/curl
./configure --prefix=/usr/local/curl --enable-ares --without-nss --with-ssl=/usr/local/openssl --with-nghttp2=/usr/local/nghttp2
make -j${cpunum}
make install
6、卸载并重新安装php
完整脚本#!/bin/bash
# 获取CPU核数
cpunum=$(cat /proc/cpuinfo | grep "processor" | wc -l)
echo "CPU 核数:$cpunum"
# 下载 nghttp2 源码
echo "正在下载 nghttp2 源码..."
wget -O nghttp2-1.42.0.tar.gz https://github.com/nghttp2/nghttp2/archive/refs/tags/v1.42.0.tar.gz
# 解压并编译安装 nghttp2
echo "解压 nghttp2 源码..."
tar -zxf nghttp2-1.42.0.tar.gz
cd nghttp2-1.42.0
echo "准备编译和安装 nghttp2..."
rm -rf /usr/local/nghttp2
autoreconf -i
automake
autoconf
./configure --prefix=/usr/local/nghttp2
make clean
echo "编译 nghttp2 中..."
make -j "$cpunum"
make install
echo "nghttp2 安装完成!"
cd ..
# 下载 curl 源码
echo "正在下载 curl 源码..."
wget https://download.bt.cn/src/curl-7.70.0.tar.gz
# 解压并编译安装 curl
echo "解压 curl 源码..."
tar -zxf curl-7.70.0.tar.gz
cd curl-7.70.0
echo "准备编译和安装 curl..."
rm -rf /usr/local/curl
./configure --prefix=/usr/local/curl --enable-ares --without-nss --with-ssl=/usr/local/openssl --with-nghttp2=/usr/local/nghttp2
echo "编译 curl 中..."
make -j "$cpunum"
make install
echo "curl 安装完成!"
# 清理下载的压缩包
echo "清理下载的压缩包..."
rm -f nghttp2-1.42.0.tar.gz curl-7.70.0.tar.gz
echo "所有操作已完成,nghttp2 和 curl 安装成功!"
楼主还在吗,按楼主的方法多次尝试后,还是无法启用http2 bylii 发表于 2022-1-7 22:54
楼主还在吗,按楼主的方法多次尝试后,还是无法启用http2
有报错信息吗 t
页:
[1]