Does changing the protocol of the aws alb taraget group to http2 improve the speed? And how to set it up?

0

I know that changing from http1 to http2 improves the speed.

So I allowed alb and cloudfront to be http2. In the developer tools of the Chrome browser, I confirmed that the protocol was h2 and http2 was applied.

However, after searching for stalled, there was an opinion that changing the protocol of the aws elb target group to http2 would improve stalled and improve speed. So I changed the protocol to http2 with the same settings as http1, but a 502 error occurred. (When connecting to a random port (eg: 8080 port) with the load balancer dns address) There was no error in the http1.1 setting.

The question is, if h2 is displayed when checking the protocol in the browser, is it applied to http2 or should the target group protocol be set to http2 internally? If I need to set it up, how can I avoid getting a 502 error?

joker
asked a year ago1307 views
1 Answer
0
Accepted Answer

When you enable ALB target group protocol as HTTP/2 you need to make sure that target support protocol version HTTP/2 as well. For example if you are using nginx you can update server section as :

server {
        listen       80 http2 ;
        listen       [::]:80 ;

If server is not configured to support protocol version, Target will send 400 bad request to ALB as ALB was making HTTP/2 request. Tested this on my env and packet capture on target show below response towards ALB.

PRI * HTTP/2.0
HTTP/1.1 400 Bad Request
Server: nginx/1.20.0
Date: Thu, 23 Feb 2023 05:06:42 GMT
Content-Type: text/html
Content-Length: 157
Connection: close

<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.20.0</center>
</body>
</html>

Request packet from ALB to Target: Enter image description here

As the ALB get this 400 Bad request from target it can generate 502 back to the client.

If you have already configured your Target for HTTP2, then you can check other possible reasons for 502 here.

As far as performance , you can get the benefit of compressed header when you have end to end HTTP2, which can save some data transfer cost.

profile pictureAWS
navaz
answered a year ago
profile picture
EXPERT
reviewed 2 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions