您的位置:首页 > 教育 > 锐评 > 中国工程造价网官网_泰安房产每日网签_体验营销策略_网络营销品牌案例

中国工程造价网官网_泰安房产每日网签_体验营销策略_网络营销品牌案例

2025/3/28 10:11:25 来源:https://blog.csdn.net/sbsy123456/article/details/146478708  浏览:    关键词:中国工程造价网官网_泰安房产每日网签_体验营销策略_网络营销品牌案例
中国工程造价网官网_泰安房产每日网签_体验营销策略_网络营销品牌案例

文章目录

  • 前言
  • 一、HTTP2测试
    • 1.1. 基本软件
    • 1.2. jansson >= 2.5(备用)
    • 1.3. libbpf-dev >= 0.7.0
    • 1.4. clang >= 15
    • 1.5. 编译官方文档(可选)
    • 1.6. aws-lc >= 1.19.0
    • 1.7. nghttp3
    • 1.8. ngtcp2
    • 1.9. nghttp2 build form source code
    • 1.10. 使用
      • 1.10.1. nghttp
      • 1.10.2. nghttpd
      • 1.10.3. nghttpx
      • 1.10.4. h2load


前言

nghttp2是Github上的一个基于C语言的HTTP/2库,可以从该库中编译出若干二进制文件形式的样例以供入门,本文参考项目说明,分享个人从软件安装到样例使用的全过程。


一、HTTP2测试

1.1. 基本软件

名称操作
pkg-config >= 0.20sudo apt install pkg-config -y && pkg-config --version
libev >= 4.11sudo apt install libev-dev
zlib >= 1.2.3sudo apt install zlib1g
libc-ares >= 1.7.5sudo apt install libc-ares-dev
libxml2 >= 2.6.26sudo apt install libxml2-dev -y
libsystemd-dev >= 209sudo apt install libsystemd-dev
libevent-openssl >= 2.0.8sudo apt install libevent-dev -y
jansson >= 2.5sudo apt install libjansson-dev
jemallocsudo apt install libjemalloc-dev -y
libbrotli-dev >= 1.0.9sudo apt install libbrotli-dev
libbpf-dev >= 0.7.0详见1.3节
libssl-devsudo apt install libssl-dev
libelf-devsudo apt install libelf-dev -y
rubysudo apt install ruby-dev -y
bisonsudo apt install bison
cmakesudo apt install cmake -y
g++ >= 12详见前一篇博客
clang++ >= 15详见1.4节

注1:如果仅编译nghttp2库,只需要pkg-config >= 0.20即可,构建时使用–enable-lib-only参数,避免可能出现的错误。

注2:如果需要构建并运行/src目录下的应用程序(nghttp,nghttpd,nghttpx和h2load),libev >= 4.11、zlib >= 1.2.3、libc-ares >= 1.7.5以及任意嵌入式SSL库(例如aws-lc >= 1.19.0,详见1.6节)是必须的。

1.2. jansson >= 2.5(备用)

如果不能apt安装jansson的版本不满足要求,则可参考该方法。

wget http://www.digip.org/jansson/releases/jansson-2.13.1.tar.gz
tar -zxvf jansson-2.13.1.tar.gz
cd jansson-2.13.1
./configure --prefix=/usr --disable-static
make && sudo make install

1.3. libbpf-dev >= 0.7.0

Ubuntu22使用apt安装的libbpf-dev为0.5.0版本,因此使用源码编译:

git clone --depth 1 -b v1.4.6 https://github.com/libbpf/libbpf
cd libbpf
PREFIX=$PWD/build make -C src install
cd ..

1.4. clang >= 15

Ubuntu22可以使用apt安装v15版本的clang和clang++,但是需要通过update-alternatives切换:

sudo apt install clang-15 -y
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-15 10 --slave /usr/bin/clang++ clang++ /usr/bin/clang++-15
sudo update-alternatives --config clang

1.5. 编译官方文档(可选)

使用以下命令在本地编译官方文档:

sudo apt install sphinx-common
sudo apt install python3-pip -y
pip install sphinx-rtd-theme
make html

文档将在/doc/manual/html/下生成。

1.6. aws-lc >= 1.19.0

git clone --depth 1 -b v1.39.0 https://github.com/aws/aws-lc
cd aws-lc
cmake -B build -DDISABLE_GO=ON --install-prefix=$PWD/opt
make -j$(nproc) -C build
cmake --install build
cd ..

1.7. nghttp3

如果想要在nghttp2项目编译出的二进制文件中使用实验性的HTTP/3协议,则需要编译nghttp3项目,详见博客使用Github项目nghttp3的样例学习HTTP/3。

1.8. ngtcp2

git clone --depth 1 -b v1.9.1 https://github.com/ngtcp2/ngtcp2
cd ngtcp2
git submodule update --init --depth 1
autoreconf -i
./configure --prefix=$PWD/build --enable-lib-only --with-boringssl \BORINGSSL_CFLAGS="-I$PWD/../aws-lc/opt/include" \BORINGSSL_LIBS="-L$PWD/../aws-lc/opt/lib -lssl -lcrypto"
make -j$(nproc)
make install
cd ..

1.9. nghttp2 build form source code

git clone https://github.com/nghttp2/nghttp2
cd nghttp2
git submodule update --init
autoreconf -i
./configure --with-mruby --enable-http3 --with-libbpf \CC=clang-15 CXX=clang++-15 \PKG_CONFIG_PATH="$PWD/../aws-lc/opt/lib/pkgconfig:$PWD/../nghttp3/build/lib/pkgconfig:$PWD/../ngtcp2/build/lib/pkgconfig:$PWD/../libbpf/build/lib64/pkgconfig" \LDFLAGS="$LDFLAGS -Wl,-rpath,$PWD/../aws-lc/opt/lib -Wl,-rpath,$PWD/../libbpf/build/lib64"
make -j$(nproc)
make check

如果编译时出现如下问题:
在这里插入图片描述
原因是有两个event.h,分别是/usr/include/event2/event.h(apt安装libevent-dev后出现)和/usr/local/include/event.h(自带)。解决方案是将其中一个删掉。

1.10. 使用

编译完成后在/src下有nghttp、nghttpd、nghttpx等二进制文件。

1.10.1. nghttp

HTTP/2客户端。用法:

./nghttp [Options] <URI>

<URI>指定要访问的URI。

1.10.2. nghttpd

HTTP/2服务端。用法:
./nghttpd [Options]… <PORT> [<PRIVATE_KEY> <CERT>]
<PORT>指定监听的端口。
<PRIVATE_KEY>设置路径以指定服务端的私钥。必须,除非--no-tls被指定。
<CERT>设置路径以指定服务端的证书。必须,除非--no-tls被指定。

1.10.3. nghttpx

nghttpx是一个支持 HTTP/3、HTTP/2 和 HTTP/1.1 的多线程反向代理。

nghttpx有两种操作模式(Operation Mode):

在这里插入图片描述
默认模式下,nghttpx作为后向服务器的反向代理(reverse proxy to the backend server),监听 HTTP/3、HTTP/2 和 HTTP/1.1,并且可以作为现有 Web 服务端的 SSL/TLS 终端进行部署。

在这里插入图片描述

在–http2-proxy模式下,nghttpx作为前向代理(forward proxy),也叫做安全的HTTP/2代理(secure HTTP/2 proxy)。

在这里插入图片描述

所有模式在默认情况下前向连接均通过SSL/TLS进行加密。若要禁用加密,需要在–frontend选项中使用no-tls关键字。若禁用了加密,则传入的HTTP/1.1连接可通过HTTP升级转换为HTTP/2。另一方面,默认情况下后向连接不加密。若要加密后向连接,需要在–backend选项中使用tls关键字。

1.10.4. h2load

HTTP/2服务端的基准测试工具。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com