簡體   English   中英

啟用HTTP2服務器推送Nginx

[英]Enable HTTP2 Server Push Nginx

我在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工具仍然確認沒有服務器推送發生。

我的理解是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)負載均衡器來實現此功能。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM