Linux 安装 http2 支持

at 6年前  ca Linux  pv 1733  by touch  


  1. 前提:服务器中已有 git,如果没有,输入下面的命令安装

sudo apt-get install -y tmux curl vim wget htop git
  1. curl请求一个需使用 http2 的网址,查看响应结果,为http1.1,说明暂时还不支持http2

vagrant@homestead:~$ curl -I https://nghttp2.org/HTTP/1.1 200 OKDate: Tue, 28 Mar 2017 04:58:27 GMT
Content-Type: text/html
Last-Modified: Mon, 27 Mar 2017 14:39:24 GMTEtag: "58d9241c-19ff"Accept-Ranges: bytes
Content-Length: 6655X-Backend-Header-Rtt: 0.001072Strict-Transport-Security: max-age=31536000Server: nghttpxVia: 2 nghttpx
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
  1. 如果强制使用http2请求,无法得到响应

vagrant@homestead:~$ curl --http2 -I https://nghttp2.org/curl: (1) Unsupported protocol
  1. 安装 nghttp2

# Get build requirements# Some of these are used for the Python bindings
# this package also installssudo apt-get install g++ make binutils autoconf automake autotools-dev libtool pkg-config \
zlib1g-dev libcunit1-dev libssl-dev libxml2-dev       libev-dev libevent-dev libjansson-dev \
libjemalloc-dev cython python3-dev python-setuptools
# Build nghttp2 from source
git clone https://github.com/tatsuhiro-t/nghttp2.git
cd nghttp2
autoreconf -i
automake
autoconf
./configure
make
sudo make install
  1. 升级最新版的 curl,这里查看curl版本

cd ~
sudo apt-get build-dep curl
wget http://curl.haxx.se/download/curl-7.xx.0.tar.bz2tar -xvjf curl-7.xx.0.tar.bz2
cd curl-7.xx.0./configure --with-nghttp2=/usr/local --with-ssl
make
sudo make install
sudo ldconfig
  1. 尝试再次连接

# Try this out firstcurl --http2 -I nghttp2.org# If you get errors, try setting this constant# to tell curl where to find shared librariesLD_LIBRARY_PATH=/usr/local/lib /usr/local/bin/curl --http2 -I nghttp2.org
  1. 连接

vagrant@homestead:~/curl-7.xx.0$ LD_LIBRARY_PATH=/usr/local/lib /usr/local/bin/curl --http2 -k -I -H "Host: example.com" https://localhost
HTTP/2.0 403
server:nginx/1.11.9
date:Tue, 28 Mar 2017 05:47:10 GMT
content-type:text/html; charset=utf-8
content-length:169
  1. 打印出phpinfo
    curl 的http2 显示 yes,表示成功。否则需要手动安装php的http扩展。



版权声明

本文仅代表作者观点,不代表码农殇立场。
本文系作者授权码农殇发表,未经许可,不得转载。

 

扫一扫在手机阅读、分享本文

已有0条评论