nginx 已经很早就支持http2,今天证书过期,重新申请了一个,同时测试下http2 的push 功能

环境准备

 
worker_processes auto;
events {
    worker_connections 65535;
}
http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;
    gzip on;
    real_ip_header X-Forwarded-For;
    server {
        listen 443 ssl http2;
        server_name dalong.apicaddy.com;
        ssl_certificate /etc/nginx/apicaddy-cert.pem;
        ssl_certificate_key /etc/nginx/apicaddy-key.pem;
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout 5m;
        ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:AES256+EDH';
        ssl_prefer_server_ciphers on;
        root /usr/share/nginx/html;
        location =/index.html {
            http2_push /index.css;
            http2_push /app.js;
            http2_push /app.css;
        }
    }
}
 
 
  • docker-compose 文件
version: "3"
services:
  nginx:
    build: ./
    volumes:
    - "./apicaddy-cert.pem:/etc/nginx/apicaddy-cert.pem"
    - "./apicaddy-key.pem:/etc/nginx/apicaddy-key.pem"
    - "./nginx.conf:/etc/nginx/nginx.conf"
    ports:
    - "443:443"
 
 
  • dockerfile
FROM nginx
COPY app.js /usr/share/nginx/html/
COPY app.css /usr/share/nginx/html/
COPY index.css /usr/share/nginx/html/
COPY index.html /usr/share/nginx/html/
 
 

测试

  • 安装nghttp2
yum  insatll nghttp2
 
  • 测试
nghttp -ans https://dalong.apicaddy.com
 
 
  • 效果
nghttp -ans https://dalong.apicaddy.com
[WARNING]: -a, --get-assets option is ignored because
the binary was not compiled with libxml2.
[WARNING] Certificate verification failed: unable to verify the first certificate
***** Statistics *****
Request timing:
  responseEnd: the time when last byte of response was received
               relative to connectEnd
 requestStart: the time just before first byte of request was sent
               relative to connectEnd. If '*' is shown, this was
               pushed by server.
      process: responseEnd - requestStart
         code: HTTP status code
         size: number of bytes received as response body without
               inflation.
          URI: request URI
see http://www.w3.org/TR/resource-timing/#processing-model
sorted by 'complete'
id responseEnd requestStart process code size request path
 13 +1.83ms +156us 1.67ms 200 209 /
  2 +1.85ms * +1.70ms 150us 200 26 /index.css
  4 +1.86ms * +1.73ms 127us 200 134 /app.js
  6 +1.88ms * +1.74ms 135us 200 37 /app.css
 

参考资料

https://www.cnblogs.com/rongfengliang/p/8579181.html
https://github.com/rongfengliang/nginx-http2-push-demo
https://www.nginx.com/blog/nginx-1-13-9-http2-server-push/

nginx http2 push 试用的更多相关文章

  1. Nginx http2.0

    109/110 HTTP2.0协议 优势必须使用TLS加密 传输数据量大幅减少 1:以二进制格式传输  2:标头压缩(header做压缩) 多路复用及相关功能 : 消息优先级 (比如样式表先渲染页面那 ...

  2. nginx brotli 压缩试用

    brotli 的压缩比相对gzip 有好多提升 测试试用docker 测试代码 https://github.com/rongfengliang/rollup-babel-demolibrary 运行 ...

  3. nginx ngx_http_image_filter_module 简单试用

    nginx包含了一个ngx_http_image_filter_module 模块,我们可以方便的进行图片的缩略图,平时一些简单的功能 已经够用了 环境准备 为了简单使用docker-compose ...

  4. nginx unit 安装试用

    1. yum 源 nano /etc/yum.repos.d/unit.repo 内容 [unit] name=unit repo baseurl=https://packages.nginx.org ...

  5. nginx unit java 试用

    unit 当前已经支持java了,当时支持基于servlet 的开发模式,以下是一个简单的学习 基于官方的demo 环境准备 docker-compose文件   version: "3&q ...

  6. http2 技术整理 nginx 搭建 http2 wireshark 抓包分析 server push 服务端推送

    使用 nginx 搭建一个 http2 的站点,准备所需: 1,域名 .com .net 均可(国内域名需要 icp 备案) 2,云主机一个,可以自由的安装配置软件的服务器 3,https 证书 ht ...

  7. nginx的安装

    1,,nginx的安装 为什么使用nginx我就不多说了,很优秀的,请再行google 在安装前,先安装pcre,安装zlib,安装openssl,以及一些其他包 yum install -y gcc ...

  8. HTTP2特性预览和抓包分析

    背景 近年来,http网络请求量日益添加,以下是httparchive统计,从2012-11-01到2016-09-01的请求数量和传输大小的趋势图: 当前大部份客户端&服务端架构的应用程序, ...

  9. openresty(nginx)、lua、drizzle调研

    一.概述: 1.研究目标:nginx中使用lua脚本,及nginx直接访问mysql,redis 2.需要安装的内容: openresty,mysql,redis 3.OpenResty (也称为 n ...

随机推荐

  1. 升级pip10.0.0后出现ModuleNotFoundError: No module named 'pip'的问题

    pip10升级后各种pip install出错----- Traceback (most recent call last): File "/usr/local/bin/pip", ...

  2. Cracking The Coding Interview 4.0_二叉树

    #include <iostream> #include <string> using namespace std; class tree { public: tree() { ...

  3. PSP0级记录2

                              上课         编写程序               课外资料               日总计     3.13 周一           ...

  4. IE浏览器兼容的处理方式之一,使用特殊的注释 <!--[if IE]> ....<![endif]-->

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. spoon 更新数据

    一个小需求,被要求使用spoon 来同步数据 主要流程为: 1.查询A库未同步数据 id 2.根据步骤1查到的id,作为条件更新B库数据 3.更新B库数据成功则更改库A中的数据状态为已同步. 4.添加 ...

  6. [转] ajax方法

    1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如 ...

  7. L265 - 5 questions to ask yourself before you ask for a raise or promotion

    You’ve been in your role for a while now, giving 110% to every assignment your manager hands out. Yo ...

  8. 爬虫框架存储pymysql方式

    爬虫框架存储pymysql方式# -*- coding: utf-8 -*-import pymysql# Define your item pipelines here## Don't forget ...

  9. 当超强台风“山竹”即将冲进南海,Power BI 你怎么看?

    这个周末“山竹 ”强势来袭!很多人的目光都在关注暴力水果“山竹”,这个号称70年最强最大风力超17级 台风“山竹”今天就已经在小悦家窗台肆虐咆哮了一天了!不知其他的小伙伴们是不是好好的一个周末就只能被 ...

  10. 2.22 JS处理富文本

    2.22 JS处理富文本 前言    <富文本>这篇解决了富文本上iframe问题,其实没什么特别之处,主要是iframe的切换,本篇讲解通过js的方法处理富文本上iframe的问题一.加 ...