【问题标题】:Enable HTTP2 Server Push Nginx启用 HTTP2 服务器推送 Nginx
【发布时间】:2019-08-11 02:16:41
【问题描述】:

我安装了支持 HTTP2 的 nginx。我的 nginx 在应用程序负载均衡器后面,SSL 终止仅在 LB 发生。

我首先启用了 HTTP2_PUSH,如下所示:

http2_push_preload on;
location /mx {
       http2_push https://example.com/css/style.css;
       http2_push https://example.com/js/main.js
}

但它没有工作。我的浏览器调试器网络选项卡显示启动器是“索引”,而 nghttp 也没有显示任何内容。

我尝试的另一种方法是:

http2_push_preload on;
    location /mx {
           add_header Link "<https://example.com/css/style.css>; rel=preload; as=style,<http2_push https://example.com/js/main.js>; rel=preload; as=script";
    }

下一个方法将网络选项卡中的启动器从 index 更改为 other,但 nghttp 工具仍然确认没有发生服务器推送。

【问题讨论】:

    标签: nginx http2 nghttp2


    【解决方案1】:

    我的理解是 AWS Application Load Balancer 是一个 7 级 (HTTP) 负载均衡器,只支持前端的 HTTP/2 而不是你的 Nginx 后端。

    您可以通过将 $server_protocol 添加到您的 Nginx log_format 来检查这一点:

    log_format my_log_format '$remote_addr - $remote_user [$time_local] $server_protocol "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"';
    access_log /usr/local/nginx/nginx-access.log my_log_format;
    

    我猜流量是以 HTTP/1.1 进入的。

    即使 AWS ALB 现在确实支持 HTTP/2 到后端,但这并不意味着它将支持 HTTP/2 推送。当像这样涉及多个基础设施时,这会变得复杂(如果 ALB 和 Nginx 都支持推送但客户端不支持),最好的建议是从边缘节点推送,特别是如果它通过 HTTP 预加载头指令支持。

    您最好使用 4 级 (TCP) 负载平衡器来使其工作。

    【讨论】:

      猜你喜欢
      • 2017-08-31
      • 2016-06-14
      • 2018-09-06
      • 2019-02-25
      • 2015-06-03
      • 2016-10-24
      • 2021-06-05
      • 2020-03-07
      • 2016-10-18
      相关资源
      最近更新 更多