0

我安装了支持 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";
    }

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

4

1 回答 1

0

我的理解是 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) 负载平衡器来使其正常工作。

于 2019-03-20T17:00:11.007 回答