zoukankan      html  css  js  c++  java
  • nginx http2 push 试用

    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/

  • 相关阅读:
    vs2017启动iis局域网无法访问解决
    centos7多节点部署redis4.0.11集群
    centos7用docker安装elasticsearch5.6.13的主从
    centos7用docker安装单节点redis4.0.11
    centos7用docker安装mysql5.7.24后配置主从
    centos7 docker 安装 mysql5.7.24 导入12G的sql
    局域网内搭建一个服务器,可以使用 https 吗
    nginx负载均衡fair模块安装和配置
    腿伤中,继续养...
    文件Move操作
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/10156093.html
Copyright © 2011-2022 走看看