博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nghttp2 和nginx的实践
阅读量:4322 次
发布时间:2019-06-06

本文共 2158 字,大约阅读时间需要 7 分钟。

主要参考https://bg2bkk.github.io/post/HTTP2%E7%9A%84%E5%AE%9E%E8%B7%B5%E8%BF%87%E7%A8%8B/,和https://fangpeishi.com/http2_proxy.html。

第三个挺有价值的链接是https://wzyboy.im/post/1052.html,但很多内容和上面的重复了。实际操作时,不必借鉴这个博客。

在/etc/pki/CA下创建初始文件

$ touch serial index.txt
$ echo 01 > serial

$ cd /etc/pki/CA

$ openssl genrsa -out private/cakey.pem 2048

使用req指令,通过私钥,生成自签证书

$ openssl req -new -x509 -key private/cakey.pem -out cacert.pem

为nginx server生成密钥

$ mkdir /root/data/nginx_ssl;cd /root/data/nginx_ssl

$ openssl genrsa -out nginx.key 2048

为nginx生成 证书签署请求

$ openssl req -new -key nginx.key -out nginx.csr

向CA请求证书

$ openssl ca -in nginx.csr -out nginx.crt 如果失败,可以尝试以下命令

$ openssl x509 -req -in nginx.csr -CA /etc/pki/CA/cacert.pem -CAkey /etc/pki/CA/private/cakey.pem -CAcreateserial -out nginx.crt

配置nginx

listen       3128;
......

server {

listen 8443 ssl http2;

ssl_certificate "/root/data/nginx_ssl/nginx.crt";

ssl_certificate_key "/root/data/nginx_ssl/nginx.key"

systemctl start nginx

用 lynx http://192.168.3.135:3128, 和 lynx https://192.168.3.135:8443 测试

接下来我们来配置nghttpx,yum -y install nghttp2

实际测试,发现在centos7下可以安装nghttp2的三个app,在centos6下,没法找到安装好的3个app。

nghttpd作为http2 server

http2-no-tls

nghttpd -v 8080   -n 24 --no-tls -d ~/workspace/Nginx_ABTesting/utils/html/

http2-with-tls

nghttpd -v 8080 -n 24 /usr/lib/ssl/nginx.key /usr/lib/ssl/nginx.crt -d ~/workspace/Nginx_ABTesting/utils/html/ 实际测试发现no-tls不work。 不关注nghttp2作为客户端的运行情况,关注nghttpx作为proxy,转向nginx后端的情况,这里主要参考开头提到的第二个链接来操作。 编辑配置文件 /etc/nghttpx/nghttpx.conf:
frontend=0.0.0.0,443backend=127.0.0.1,3128private-key-file=/root/data/nginx_ssl/nginx.keycertificate-file=/root/data/nginx_ssl/nginx.crthttp2-proxy=yeserrorlog-syslog=yesworkers=1add-x-forwarded-for=nono-via=yesno-ocsp=yes#tls-proto-list=TLSv1.2tls-min-proto-version=TLSv1.0tls-max-proto-version=TLSv1.2ciphers=ECDHE+AES128

这个是通过测试的。原来配的backend的端口是8443,发现无法work。

tls-proto-list=TLSv1.2提示“deprecated”,修改为...min...和...max.... 作为服务,systemctl restart nghttpx 这样启动nghttpx更合适。

最终测试: https://192.168.3.135, 135机器上,443作为nghttpx的前端,收到request,转发到3128上,nginx正好监听这个端口,处理后,把主页返回到客户端浏览器。浏览器必须

是支持http2的浏览器,chrome或者firefox。

 

转载于:https://www.cnblogs.com/tangxiaosheng/p/9681049.html

你可能感兴趣的文章
【设计模式】 访问者模式
查看>>
关于FFMPEG 中I帧、B帧、P帧、PTS、DTS
查看>>
request和response的知识
查看>>
bootstrap 表单类
查看>>
20165332第四周学习总结
查看>>
Codeforces Round #200 (Div. 1)D. Water Tree dfs序
查看>>
linux安全设置
查看>>
Myflight航班查询系统
查看>>
团队-团队编程项目爬取豆瓣电影top250-代码设计规范
查看>>
表头固定内容可滚动表格的3种实现方法
查看>>
想对你说
查看>>
day5 面向对象
查看>>
{算法}Young司机带你轻松KMP
查看>>
不同方法获得视差图比较
查看>>
jQuery笔记(二)
查看>>
Velocity模版进行shiro验证
查看>>
新生舞会
查看>>
c++实现单向链表的一些操作
查看>>
Vim中无法用Alt键来映射
查看>>
ubuntu硬件配置查看命令
查看>>