nghttp2 和nginx的实践
主要参考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,
backend=127.0.0.1,
private-key-file=/root/data/nginx_ssl/nginx.key
certificate-file=/root/data/nginx_ssl/nginx.crt
http2-proxy=yes
errorlog-syslog=yes
workers= add-x-forwarded-for=no no-via=yes
no-ocsp=yes
#tls-proto-list=TLSv1.
tls-min-proto-version=TLSv1.
tls-max-proto-version=TLSv1.
ciphers=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。
最新文章
- 微信小程序的机会在于重新理解群组与二维码
- cg数据类型
- UNITY自带的PACKAGE的UTILITY 里面有一个自带的FPS COUNTER
- 鼠标点击输入框文字消失 value placeholder 以及JQ实现效果 (仿京东的输入框效果)
- winform 映射字段的写法:
- 引用类型传递 ListView展示数据
- Algorithm -->; 十大排序算法
- Hadoop--之RPC开发
- web框架-Struts开始
- ASP.NET WEB API 返回JSON 出现2个双引号问题
- foreach写失效的问题
- for 循环使用 enumerate 以及yield生成器简单例子
- javascript精雕细琢(四):认亲大戏——通过console.log彻底搞清this
- WebApi Owin SelfHost OAuth2 - 授权服务和资源服务分离方案
- golang test cannot find import
- Win7如何自定义桌面右键菜单
- a标签上的点击事件
- oracle 集群jndi部署方式
- Spring 事务管理高级应用难点剖析: 第 1 部分
- JAVA常用知识总结(三)——JAVA虚拟机
热门文章
- AICODER全栈实习报名
- mybatis generator生成文件大小写问题
- Android开发怎么让自己的APP UI漂亮、大方(配色篇二)
- WPS Office手机版调用接口代码指导帖之二 [复制链接]
- laravel5.8笔记三:常用命令
- java如何对List集合中的元素进行排序(请收藏)
- Windows下Codeblocks调试Cocos2d-x项目体验(一次失败的体验)
- thinkcmf 5关闭后台验证码
- js中 函数参数的 传值/传引用 问题
- HTML <;script>; 标签的 defer 和 async 属性